{"library":"py-solc-x","title":"Py Solc X","description":"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.","language":"python","status":"active","last_verified":"Fri Apr 17","install":{"commands":["pip install py-solc-x"],"cli":{"name":"solc","version":"sh: 1: solc: not found"}},"imports":["import solcx","from solcx import compile_source"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import solcx\nimport os\n\nsolidity_code = '''\npragma solidity ^0.8.0;\n\ncontract SimpleStorage {\n    uint256 public storedData;\n\n    constructor(uint256 initialData) {\n        storedData = initialData;\n    }\n\n    function set(uint256 x) public {\n        storedData = x;\n    }\n\n    function get() public view returns (uint25n) {\n        return storedData;\n    }\n}\n'''\n\n# Ensure a solc version is installed\n# Using os.environ.get for an example, in real use specify a version like '0.8.10'\ntarget_version = os.environ.get('SOLC_VERSION', '0.8.10')\n\nif not solcx.get_installed_solc_versions():\n    print(f\"No solc versions found. Installing {target_version}...\")\n    solcx.install_solc(target_version)\n\n# Select the desired solc version. This is crucial.\nsolcx.set_solc_version(target_version)\nprint(f\"Using solc version: {solcx.get_solc_version()}\")\n\n# Compile the Solidity code\ncompiled_sol = solcx.compile_source(\n    solidity_code,\n    output_values=['abi', 'bin']\n)\n\n# Extract contract data\ncontract_name = '<stdin>:SimpleStorage'\ncontract_abi = compiled_sol[contract_name]['abi']\ncontract_bytecode = compiled_sol[contract_name]['bin']\n\nprint(\"\\n--- Compiled Contract ABI ---\")\nprint(contract_abi)\nprint(\"\\n--- Compiled Contract Bytecode ---\")\nprint(contract_bytecode[:60] + '...') # Print first 60 chars of bytecode for brevity","lang":"python","description":"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}