Skip to main content

Python wrapper around the solc binary

Project description

# py-solc

[![Build Status](https://travis-ci.org/pipermerriam/py-solc.png)](https://travis-ci.org/pipermerriam/py-solc)
[![PyPi version](https://pypip.in/v/py-solc/badge.png)](https://pypi-hypernode.com/pypi/py-solc)
[![PyPi downloads](https://pypip.in/d/py-solc/badge.png)](https://pypi-hypernode.com/pypi/py-solc)


Python wrapper around the `solc` Solidity compiler.


# Dependency

This library requires the `solc` executable to be present.

Only versions `>=0.4.2` are supported and tested though this library may work
with other versions.

[solc installation instructions](http://solidity.readthedocs.io/en/latest/installing-solidity.html)


# Quickstart

Installation

```sh
pip install py-solc
```

Or to install with support for gevent

```sh
pip install py-solc[gevent]
```

To enable gevent subprocessing set the environment variable `SOLC_THREADING_BACKEND=gevent`


## Standard JSON Compilation

Use the `solc.compile_standard` function to make use the [standard-json] compilation feature.

[Solidity Documentation for Standard JSON input and ouptup format](http://solidity.readthedocs.io/en/develop/using-the-compiler.html#compiler-input-and-output-json-description)

```
>>> from solc import compile_standard
>>> compile_standard({
... 'language': 'Solidity',
... 'sources': {'Foo.sol': 'content': "...."},
... })
{
'contracts': {...},
'sources': {...},
'errors': {...},
}
>>> compile_standard({
... 'language': 'Solidity',
... 'sources': {'Foo.sol': 'urls': ["/path/to/my/sources/Foo.sol"]},
... }, allow_paths="/path/to/my/sources")
{
'contracts': {...},
'sources': {...},
'errors': {...},
}
```


## Legacy Combined JSON compilation


```python
>>> from solc import compile_source, compile_files, link_code
>>> compile_source("contract Foo { function Foo() {} }")
{
'Foo': {
'abi': [{'inputs': [], 'type': 'constructor'}],
'code': '0x60606040525b5b600a8060126000396000f360606040526008565b00',
'code_runtime': '0x60606040526008565b00',
'source': None,
'meta': {
'compilerVersion': '0.3.5-9da08ac3',
'language': 'Solidity',
'languageVersion': '0',
},
},
}
>>> compile_files(["/path/to/Foo.sol", "/path/to/Bar.sol"])
{
'Foo': {
'abi': [{'inputs': [], 'type': 'constructor'}],
'code': '0x60606040525b5b600a8060126000396000f360606040526008565b00',
'code_runtime': '0x60606040526008565b00',
'source': None,
'meta': {
'compilerVersion': '0.3.5-9da08ac3',
'language': 'Solidity',
'languageVersion': '0',
},
},
'Bar': {
'abi': [{'inputs': [], 'type': 'constructor'}],
'code': '0x60606040525b5b600a8060126000396000f360606040526008565b00',
'code_runtime': '0x60606040526008565b00',
'source': None,
'meta': {
'compilerVersion': '0.3.5-9da08ac3',
'language': 'Solidity',
'languageVersion': '0',
},
},
}
>>> unlinked_code = "606060405260768060106000396000f3606060405260e060020a6000350463e7f09e058114601a575b005b60187f0c55699c00000000000000000000000000000000000000000000000000000000606090815273__TestA_________________________________90630c55699c906064906000906004818660325a03f41560025750505056"
>>> link_code(unlinked_code, {'TestA': '0xd3cda913deb6f67967b99d67acdfa1712c293601'})
... "606060405260768060106000396000f3606060405260e060020a6000350463e7f09e058114601a575b005b60187f0c55699c00000000000000000000000000000000000000000000000000000000606090815273d3cda913deb6f67967b99d67acdfa1712c29360190630c55699c906064906000906004818660325a03f41560025750505056"
```

## Setting the path to the `solc` binary

You can use the environment variable `SOLC_BINARY` to set the path to your solc binary.


## Installing the `solc` binary

> This feature is experimental and subject to breaking changes.

Any of the following versions of `solc` can be installed using `py-solc` on the
listed platforms.

* `v0.4.1` (linux)
* `v0.4.2` (linux)
* `v0.4.6` (linux)
* `v0.4.7` (linux)
* `v0.4.8` (linux/osx)
* `v0.4.9` (linux)
* `v0.4.11` (linux/osx)
* `v0.4.12` (linux/osx)

Installation can be done via the command line:

```bash
$ python -m solc.install v0.4.12
```

Or from python using the `install_solc` function.

```python
>>> from solc import install_solc
>>> install_solc('v0.4.12')
```

The installed binary can be found under your home directory. The `v0.4.12`
binary would be located at `$HOME/.py-solc/solc-v0.4.12/bin/solc`. Older linux
installs will also require that you set the environment variable
`LD_LIBRARY_PATH=$HOME/.py-solc/solc-v0.4.12/bin`


## Import path remappings

`solc` provides path aliasing allow you to have more reusable project configurations.

You can use this like:

```
from solc import compile_source, compile_files, link_code

compile_files([source_file_path], import_remappings=["zeppeling=/my-zeppelin-checkout-folder"])
```

[More information about solc import aliasing](http://solidity.readthedocs.io/en/develop/layout-of-source-files.html#paths)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py-solc-1.2.1.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

py_solc-1.2.1-py2-none-any.whl (14.1 kB view details)

Uploaded Python 2

File details

Details for the file py-solc-1.2.1.tar.gz.

File metadata

  • Download URL: py-solc-1.2.1.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for py-solc-1.2.1.tar.gz
Algorithm Hash digest
SHA256 bbc8e0d4d8159d965beacebb51bfe7b19c819e2a42be4003af47677ecc447fcf
MD5 f91d0d635ab8e4fd337c8e22415e7481
BLAKE2b-256 c57751d69809c2e680e3864fe5e5e166b522b97ecfba350d3f182cd8c46f14d6

See more details on using hashes here.

File details

Details for the file py_solc-1.2.1-py2-none-any.whl.

File metadata

File hashes

Hashes for py_solc-1.2.1-py2-none-any.whl
Algorithm Hash digest
SHA256 8cc4e204be0ac38f15cda0345eb7e8cae21b675e051381a130dee2a0ec6dbcc4
MD5 a0db14be1b141495442043a7a9163a64
BLAKE2b-256 ac92f0e460be4cb0ab302ce5547e0669b3aedae61a382f73fc8702f534b474d0

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page