Ethereum Python Ecosystem Tour

There's a lot of puzzle pieces around here. Let's take a look at what each Python tool does, why it exists, and how to get started. Note that this will probably never be an exhaustive list, but ping me if you want to suggest the inclusion of another tool. At the end of the post, we'll discuss how to put the pieces together to build your own project.

web3.py

What?

web3.py is a flexible library for interacting with Ethereum. It can be used to read blockchain data, manage accounts, and send transactions. web3.py also makes use of a number of utility libraries for data formatting and encoding, account management, type hints, and more, which you're also free to utilize in isolation (see: dependencies).

Dependencies: eth-account, eth-abi, eth-utils, hexbytes, eth-typing

Why?

Ethereum clients communicate over JSON-RPC. Manually assembling JSON-RPC requests is an unreasonable developer experience, so web3.py provides a more human-friendly interface for communicating with an Ethereum node. (For a deep dive under the hood, see this blog post.)

How to get started?

py-evm

What?

py-evm is a Python implementation of the Ethereum Virtual Machine (EVM). The EVM is the software that performs the actual execution of opcodes and state transitions required by transactions.

Dependencies: py-trie, eth-bloom, eth-keys, eth-typing, eth-utils, pyrlp

Why?

EVM implementations are written in many languages. The Python version is used for local test environments (see: eth-tester), protocol research (i.e., experimenting with changes to the protocol), and local testing in Python (see: Titanoboa).

How to get started?

eth-tester

What?

eth-tester is a local test blockchain network that comes standard out of the box for web3.py (via EthereumTesterProvider) and the Ape framework, introduced in the next section. Under the hood, the EthereumTesterProvider takes requests made by web3.py and executes them locally using py-evm, simulating a live network.

Dependencies: eth-account, eth-abi, eth-keys, eth-utils, pyrlp

Why?

Installing more tools, then configuring and connecting to a provider is a lot for newcomers to navigate. Having a (relatively) simple test network available by default is a more gentle way to learn the ropes.

How to get started?

Ape

What?

Ape is a smart contract development framework for Python devs. It provides a specialized environment for developing, testing, and deploying smart contracts.

Dependencies: web3.py, eth-tester, py-evm, eth-account, eth-abi, eth-utils, hexbytes, ethpm-types

Why?

Smart contract frameworks offer powerful and convenient features on top of lower-level tools, like web3.py, eth-account, and py-evm. Prior Python frameworks (Populous, Brownie) have had less configurable, more monolithic architectures. Drawing inspiration from Hardhat, Ape offers a plugin-based architecture, so that developers can easily swap out old tools for new ones.

How to get started?

Wake

What?

Wake is a newer smart contract development framework specific to Solidity. It checks many of the same boxes as Ape, but makes trade-offs associated with only serving Solidity developers.

Dependencies: eth-account, eth-abi, eth-utils

Why?

Wake maintainers are creating an optimized experience for Solidity developers. Beyond the framework fundamentals (compiling, deploying, network and account management), their toolset includes Solidity-specific vulnerability detection, debugging tools, coverage analysis, and performance optimizations.

How to get started?

Vyper

What?

Vyper is a Pythonic EVM smart contract language.

Why?

Healthy ecosystems have competition. Vyper is a Pythonic alternative to the JavaScript-inspired syntax of Solidity. The differences go beyond syntax, however. The Vyper team has its own guiding Principles and Goals, and makes a number of trade-offs in the name of security and developer experience.

How to get started?

Titanoboa

What?

Titanoboa is a Vyper interpreter. The short version: it lets you compile and test Vyper code. The longer version, provided in the GitHub repo:

Internally, titanoboa uses vyper as a library to compile source code to bytecode, and then runs the bytecode using py-evm, adding instrumenting hooks to provide introspection. The use of py-evm means that the entire experience is highly configurable, down to the ability to patch opcodes and precompiles at the EVM level.

Why?

Titanoboa offers super-powered testing of Vyper contracts. The tool makes it trivial set up environments with arbitrary blockchain and account state, so that complex test cases are easier to write, read, and manage.

How to get started?

Tying it all together

Are you still wondering which tools to choose for your own project? Here's a quick decision guide:

1) If you're just learning the basics of Ethereum and don't have a project idea in mind yet, start by:

  • reading this introductory blog series,
  • experimenting with web3.py to query block data and interact with a test network, then
  • give Ape or Woke a try when you're ready to write your first smart contract.

2) If you're focused on blockchain data analysis, writing scripts using web3.py may cover all your bases. Testing can all by done using pytest.

3) If you're interested in writing, testing, or deploying contracts, initialize an Ape or Woke project. Bonus points for trying out Vyper and testing the code with pytest and Titanoboa.

*) You need only reach directly for py-evm, eth-tester, or one of the other utility libraries if you want to get deeper in the weeds for learning or research purposes, or you're in the business of building developer tools yourself.

That's a good starting point! See you in those Discord communities when you're ready with more questions or want to share what you're building. 🚀