[](https://travis-ci.org/pipermerriam/py-solc)
[](https://pypi.python.org/pypi/py-solc)
[](https://pypi.python.org/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)
* `v0.4.13` (linux/osx)
* `v0.4.14` (linux/osx)
* `v0.4.15` (linux/osx)
* `v0.4.16` (linux/osx)
* `v0.4.17` (linux/osx)
Installation can be done via the command line:
```bash
$ python -m solc.install v0.4.17
```
Or from python using the `install_solc` function.
```python
>>> from solc import install_solc
>>> install_solc('v0.4.17')
```
The installed binary can be found under your home directory. The `v0.4.17`
binary would be located at `$HOME/.py-solc/solc-v0.4.17/bin/solc`. Older linux
installs will also require that you set the environment variable
`LD_LIBRARY_PATH=$HOME/.py-solc/solc-v0.4.17/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)
Metadata
Release files for py-solc 1.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| py-solc-1.4.0.tar.gz | 10.4 kB | Without provenance | Details for py-solc-1.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| py_solc-1.4.0-py3-none-any.whl | Python 3 | none | any | Details for py_solc-1.4.0-py3-none-any.whl |
Total release size: 24.6 kB
Release files / py-solc-1.4.0.tar.gz
| Download URL | py-solc-1.4.0.tar.gz |
|---|---|
| Size | 10.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7da4a45451b93e91b44870d4b78d0283e1fcc963695c1975c92988eda572aa51
|
|
BLAKE2b-256 checksum How to use checksums |
9583cb47c1c13bd94780ea1399b00e3a35f0f284c8701026af651ceac54d69da
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / py_solc-1.4.0-py3-none-any.whl
| Download URL | py_solc-1.4.0-py3-none-any.whl |
|---|---|
| Size | 14.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9fc41527c4c719de039273bffb1764c3062c799f7034593234a22beebeb8ff20
|
|
BLAKE2b-256 checksum How to use checksums |
b28c34b3aa56d19b95cdad8349ab392fcfdcdd87a828b1b7709717b661627265
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for py-solc 1.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.