py-solc-x is a Python wrapper and version management tool for the `solc` Solidity compiler. It simplifies the installation, management, and use of multiple `solc` versions, allowing developers to compile Solidity code directly from Python. The current version is 2.0.5, and it sees frequent minor updates for bug fixes and occasional feature releases.
pip install py-solc-xVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to install a specific `solc` version, set it as the active compiler, and then compile a simple Solidity contract source code using `py-solc-x`. It outputs the contract's ABI and bytecode.
Review how `solc` versions are parsed and compared in your application. Ensure they are compatible with `packaging.Version`'s parsing logic. Direct usage of `solcx.set_solc_version` should still work with standard version strings, but be aware of stricter internal checks.
Ensure network access to `binaries.soliditylang.org` is permitted. If manual binary management is required, consider using `solcx.set_solc_path()` after downloading the binary yourself.
Upgrade to `py-solc-x` v2.0.1 or newer to gain access to `solcx.select_pragma_version` for easier pragma-based version selection.
Upgrade to `py-solc-x` v1.1.0 or newer when compiling Solidity contracts written for version 0.8.0 or later to ensure correct ABI generation.
Call `solcx.install_solc('X.Y.Z')` to download and install a specific `solc` version, where 'X.Y.Z' is the desired version (e.g., '0.8.10'). Alternatively, if `solc` is already installed elsewhere, use `solcx.set_solc_path('/path/to/solc')`.Inspect the full `Output:` and `Error:` messages from the `SolcError` for specific details from the `solc` compiler. Correct any Solidity syntax errors, ensure all imported files are accessible, and verify that the `solcx.set_solc_version()` call selects a `solc` compiler version that matches your contract's `pragma solidity`.
Ensure that the `solc` version you have selected with `solcx.set_solc_version()` (or that `py-solc-x` automatically selects) falls within the range specified by your contract's `pragma solidity`. You might need to `solcx.install_solc('X.Y.Z')` and then `solcx.set_solc_version('X.Y.Z')` to use a compatible compiler.No dependency data recorded yet.