ethereum/web3.py

Name: web3.py

Owner: ethereum

Description: A python interface for interacting with the Ethereum blockchain and ecosystem.

Created: 2016-04-14 15:59:35.0

Updated: 2018-05-24 10:39:02.0

Pushed: 2018-05-24 10:51:27.0

Homepage: http://web3py.readthedocs.io

Size: 2472

Language: Python

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Web3.py

Join the chat at https://gitter.im/ethereum/web3.py

Build Status

A Python implementation of web3.js

Read more in the documentation on ReadTheDocs. View the change log on Github.

Quickstart
rt json
rt web3

 web3 import Web3, HTTPProvider, TestRPCProvider
 solc import compile_source
 web3.contract import ConciseContract

lidity source code
ract_source_code = '''
ma solidity ^0.4.0;

ract Greeter {
string public greeting;

function Greeter() {
    greeting = 'Hello';
}

function setGreeting(string _greeting) public {
    greeting = _greeting;
}

function greet() constant returns (string) {
    return greeting;
}



iled_sol = compile_source(contract_source_code) # Compiled source code
ract_interface = compiled_sol['<stdin>:Greeter']

b3.py instance
 Web3(TestRPCProvider())

stantiate and deploy contract
ract = w3.eth.contract(abi=contract_interface['abi'], bytecode=contract_interface['bin'])

t transaction hash from deployed contract
ash = contract.deploy(transaction={'from': w3.eth.accounts[0], 'gas': 410000})

t tx receipt to get contract address
eceipt = w3.eth.getTransactionReceipt(tx_hash)
ract_address = tx_receipt['contractAddress']

ntract instance in concise mode
= contract_interface['abi']
ract_instance = w3.eth.contract(address=contract_address, abi=abi,ContractFactoryClass=ConciseContract)

tters + Setters for web3.eth.contract object
t('Contract value: {}'.format(contract_instance.greet()))
ract_instance.setGreeting('Nihao', transact={'from': w3.eth.accounts[0]})
t('Setting value to: Nihao')
t('Contract value: {}'.format(contract_instance.greet()))
Developer Setup
clone git@github.com:ethereum/web3.py.git
eb3.py

Please see OS-specific instructions for:

Then run these install commands:

ualenv venv
nv/bin/activate
install -e .[tester] -r requirements-dev.txt

For different environments, you can set up multiple virtualenv. For example, if you want to create a venvdocs, then you do the following:

ualenv venvdocs
nvdocs/bin/activate
install -r requirements-docs.txt
install -e .
Using Docker

If you would like to develop and test inside a Docker environment, use the sandbox container provided in the docker-compose.yml file.

To start up the test environment, run:

er-compose up -d

This will build a Docker container set up with an environment to run the Python test code.

Note: This container does not have go-ethereum installed, so you cannot run the go-ethereum test suite.

To run the Python tests from your local machine:

er-compose exec sandbox bash -c 'pytest -n 4 -f -k "not goethereum"'

You can run arbitrary commands inside the Docker container by using the bash -c prefix.

er-compose exec sandbox bash -c ''

Or, if you would like to just open a session to the container, run:

er-compose exec sandbox bash
Testing Setup

During development, you might like to have tests run on every file save.

Show flake8 errors on file change:

st flake8
-changed -v -s -r -1 web3/ tests/ ens/ -c "clear; flake8 web3 tests ens && echo 'flake8 success' || echo 'error'"

You can use pytest-watch, running one for every Python environment:

install pytest-watch

env
--onfail "notify-send -t 5000 'Test failure ?????' 'python 3 test on web3.py failed'" ../tests ../web3

Or, you can run multi-process tests in one command, but without color:

 the project root:
st --numprocesses=4 --looponfail --maxfail=1
e same thing, succinctly:
st -n 4 -f --maxfail=1
How to Execute the Tests?
  1. Setup your development environment.

  2. Execute tox for the tests

There are multiple components of the tests. You can run test to against specific component. For example:

n Tests for the Core component (for Python 3.5):
-e py35-core

n Tests for the Core component (for Python 3.6):
-e py36-core

If for some reason it is not working, add --recreate params.

tox is good for testing against the full set of build targets. But if you want to run the tests individually, py.test is better for development workflow. For example, to run only the tests in one file:

est tests/core/gas-strategies/test_time_based_gas_price_strategy.py
Release setup

For Debian-like systems:

install pandoc

To release a new version:

 release bump=$$VERSION_PART_TO_BUMP$$
How to bumpversion

The version format for this repo is {major}.{minor}.{patch} for stable, and {major}.{minor}.{patch}-{stage}.{devnum} for unstable (stage can be alpha or beta).

To issue the next version in line, specify which part to bump, like make release bump=minor or make release bump=devnum.

If you are in a beta version, make release bump=stage will switch to a stable.

To issue an unstable version when the current version is stable, specify the new version explicitly, like make release bump="--new-version 4.0.0-alpha.1 devnum"


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.