Optimism
Pronto para usar isso em produção?
O plano gratuito cobre projetos pessoais. O pay-as-you-go escala sem cartão de crédito.
Optimism
O plano gratuito cobre projetos pessoais. O pay-as-you-go escala sem cartão de crédito.
Python's OP Mainnet tooling splits cleanly by job: web3.py handles general scripting and application code — reading balances, signing ETH transfers, calling contracts on chain ID 10 — while eth-brownie wraps a full smart-contract development workflow with testing and deployment built in. Because OP Mainnet is EVM-equivalent, both libraries work against it exactly as they do on Ethereum L1, scaling from a five-line balance script up to a complex production backend.
web3.py 6+ offers both a synchronous and an async interface, so you can keep simple OP Mainnet scripts blocking and straightforward while still scaling concurrent workloads when you need them. The async path requires AsyncWeb3 paired with an async-compatible provider — it is not just a flag on the regular client.
web3.py is the canonical Python library for OP Mainnet, exposing the full JSON-RPC API surface through a Pythonic interface. Install it with pip install web3, then connect by handing the endpoint to an HTTP provider: Web3(Web3.HTTPProvider('https://optimism.therpc.io/YOUR_API_KEY')). The resulting web3 object is your gateway to chain ID 10 — web3.eth.get_balance, web3.eth.gas_price, transaction submission, and everything else.
eth-brownie is a Python framework built around the smart-contract lifecycle on OP Mainnet — writing, testing, and deploying Solidity with a Python-native test runner and an interactive console. Install it with pip install eth-brownie, and point its network config at your OP Mainnet endpoint to compile, deploy, and exercise contracts against chain ID 10.
The async interface centers on AsyncWeb3, which lets you fire many OP Mainnet calls concurrently instead of waiting on each in turn — a big win when you are pulling a range of blocks or many account balances at once. It requires an async-compatible provider and runs inside an asyncio event loop, so structure your code with async def and await and drive it through asyncio.run.
web3.py ships comprehensive type stubs, so you can annotate OP Mainnet code with TxParams, Wei, and Address imported from web3.types. Those annotations unlock IDE autocompletion and let mypy catch mistakes statically — for instance flagging a plain int passed where a Wei value is expected before it ever reaches the network.