Python wrapper and version management tool for the solc Solidity compiler.
77
Evaluation — 77%
↑ 1.05xAgent success when using this tile
Comprehensive version management system for installing, managing, and switching between different versions of the Solidity compiler. Supports downloading precompiled binaries, compiling from source, and pragma-based version selection.
Download and install precompiled versions of the Solidity compiler from the official Ethereum release channel.
def install_solc(
version: Union[str, Version] = "latest",
show_progress: bool = False,
solcx_binary_path: Optional[Union[Path, str]] = None,
) -> Version:
"""
Download and install a precompiled version of solc.
Parameters:
- version: Version to install ('latest' or specific version like '0.8.19')
- show_progress: Show download progress bar (requires tqdm package)
- solcx_binary_path: Custom installation directory path
Returns:
Version object of installed solc version
Raises:
SolcInstallationError: Installation failed
ConnectionError: Network/download error
UnsupportedVersionError: Version not supported
"""Usage example:
import solcx
# Install latest version
latest_version = solcx.install_solc()
print(f"Installed: {latest_version}")
# Install specific version
solcx.install_solc('0.8.19')
# Install with progress bar (requires: pip install tqdm)
solcx.install_solc('0.7.6', show_progress=True)
# Install to custom directory
solcx.install_solc('0.8.0', solcx_binary_path='/custom/path/solc')Install Solidity by downloading and compiling source code. Available on Linux and macOS only.
def compile_solc(
version: Optional[Union[str, Version]] = None,
show_progress: bool = False,
solcx_binary_path: Optional[Union[Path, str]] = None,
) -> Version:
"""
Install solc by downloading and compiling source code.
Parameters:
- version: Version to compile ('latest', None, or specific version)
- show_progress: Show download progress bar
- solcx_binary_path: Custom installation directory path
Returns:
Version object of compiled solc version
Raises:
OSError: Not supported on Windows
SolcInstallationError: Compilation failed
ConnectionError: Network/download error
"""Usage example:
import solcx
# Compile latest version from source (Linux/macOS only)
try:
version = solcx.compile_solc()
print(f"Compiled from source: {version}")
except OSError as e:
print("Source compilation not supported on this platform")
# Compile specific version
solcx.compile_solc('0.8.19')Get lists of available, installable, and already installed Solidity versions.
def get_installable_solc_versions() -> List[Version]:
"""
Return list of all solc versions that can be installed.
Returns:
List of Version objects for installable versions
Raises:
ConnectionError: Network error fetching version list
"""
def get_compilable_solc_versions(
headers: Optional[Dict] = None,
rate_limit_wait_time: float = 3.0
) -> List[Version]:
"""
Return list of all solc versions that can be compiled from source.
Parameters:
- headers: HTTP headers for GitHub API requests
- rate_limit_wait_time: Wait time for rate limiting
Returns:
List of Version objects for compilable versions
Raises:
OSError: Not supported on Windows
ConnectionError: Network error or GitHub API issues
"""
def get_installed_solc_versions(
solcx_binary_path: Optional[Union[Path, str]] = None
) -> List[Version]:
"""
Return list of currently installed solc versions.
Parameters:
- solcx_binary_path: Custom installation directory path
Returns:
List of Version objects for installed versions
"""Usage example:
import solcx
# Get all installable versions
installable = solcx.get_installable_solc_versions()
print(f"Available versions: {installable[:5]}...") # First 5
# Get compilable versions (Linux/macOS only)
try:
compilable = solcx.get_compilable_solc_versions()
print(f"Compilable versions: {compilable[:3]}...")
except OSError:
print("Source compilation not supported")
# Get installed versions
installed = solcx.get_installed_solc_versions()
print(f"Installed versions: {installed}")
# Check if specific version is installed
if Version('0.8.19') in installed:
print("Version 0.8.19 is installed")Set the active Solidity compiler version for compilation operations.
def set_solc_version(
version: Union[str, Version],
silent: bool = False,
solcx_binary_path: Optional[Union[Path, str]] = None,
) -> None:
"""
Set the currently active solc binary.
Parameters:
- version: Version to activate
- silent: Suppress logging output
- solcx_binary_path: Custom installation directory path
Raises:
SolcNotInstalled: Version not installed
UnsupportedVersionError: Version not supported
"""
def get_solcx_install_folder(
solcx_binary_path: Optional[Union[Path, str]] = None
) -> Path:
"""
Return directory where py-solc-x stores installed solc binaries.
Parameters:
- solcx_binary_path: Custom path override
Returns:
Path to installation directory (default: ~/.solcx)
"""Usage example:
import solcx
# Install and set version
solcx.install_solc('0.8.19')
solcx.set_solc_version('0.8.19')
# Silent mode (no logging)
solcx.set_solc_version('0.7.6', silent=True)
# Check install folder
install_path = solcx.get_solcx_install_folder()
print(f"Solc binaries stored in: {install_path}")
# Custom install folder
custom_path = solcx.get_solcx_install_folder('/custom/path')
print(f"Custom path: {custom_path}")Automatically select and install Solidity versions based on pragma statements in source code.
def set_solc_version_pragma(
pragma_string: str,
silent: bool = False,
check_new: bool = False
) -> Version:
"""
Set active solc binary based on pragma statement.
Parameters:
- pragma_string: Pragma statement (e.g., "pragma solidity ^0.8.0;")
- silent: Suppress logging output
- check_new: Check for newer compatible versions
Returns:
Version object of selected version
Raises:
SolcNotInstalled: No compatible version installed
"""
def install_solc_pragma(
pragma_string: str,
install: bool = True,
show_progress: bool = False,
solcx_binary_path: Optional[Union[Path, str]] = None,
) -> Version:
"""
Find and optionally install latest compatible solc version based on pragma.
Parameters:
- pragma_string: Pragma statement
- install: Whether to install the version
- show_progress: Show download progress bar
- solcx_binary_path: Custom installation directory path
Returns:
Version object of compatible version
Raises:
UnsupportedVersionError: No compatible version exists
"""Usage example:
import solcx
# Set version based on pragma
pragma = "pragma solidity ^0.8.0;"
version = solcx.set_solc_version_pragma(pragma)
print(f"Selected version: {version}")
# Install latest compatible version for pragma
pragma = "pragma solidity >=0.7.0 <0.9.0;"
latest_compatible = solcx.install_solc_pragma(pragma, show_progress=True)
print(f"Installed: {latest_compatible}")
# Just find compatible version without installing
pragma = "pragma solidity ~0.8.19;"
compatible = solcx.install_solc_pragma(pragma, install=False)
print(f"Compatible version found: {compatible}")
# Complex pragma with OR conditions
pragma = "pragma solidity ^0.8.0 || ^0.7.0;"
version = solcx.install_solc_pragma(pragma)
print(f"Selected from multiple ranges: {version}")Import and copy existing Solidity installations into py-solc-x's managed directory.
def import_installed_solc(
solcx_binary_path: Optional[Union[Path, str]] = None
) -> List[Version]:
"""
Search for and copy installed solc versions into local installation folder.
Parameters:
- solcx_binary_path: Custom installation directory path
Returns:
List of Version objects for imported versions
"""Usage example:
import solcx
# Import system-installed solc versions
imported = solcx.import_installed_solc()
if imported:
print(f"Imported versions: {imported}")
else:
print("No existing installations found")
# Import to custom directory
imported = solcx.import_installed_solc(solcx_binary_path='/custom/path')
print(f"Imported to custom location: {imported}")py-solc-x respects the following environment variables:
SOLCX_BINARY_PATH: Override default installation directory (default: ~/.solcx)GITHUB_TOKEN: GitHub API token for avoiding rate limits when fetching version infoimport os
import solcx
# Set custom binary path via environment
os.environ['SOLCX_BINARY_PATH'] = '/opt/solc'
install_path = solcx.get_solcx_install_folder()
print(f"Install path: {install_path}") # /opt/solc
# Set GitHub token to avoid rate limits
os.environ['GITHUB_TOKEN'] = 'your_github_token_here'
compilable = solcx.get_compilable_solc_versions()Version management functions raise specific exceptions:
import solcx
from solcx import SolcNotInstalled, SolcInstallationError, UnsupportedVersionError
try:
# This might fail if version isn't installed
solcx.set_solc_version('0.8.99')
except SolcNotInstalled as e:
print(f"Version not installed: {e}")
try:
# This might fail if version doesn't exist
solcx.install_solc('0.99.99')
except SolcInstallationError as e:
print(f"Installation failed: {e}")
try:
# This might fail for old versions
solcx.install_solc('0.3.0')
except UnsupportedVersionError as e:
print(f"Version not supported: {e}")Install with Tessl CLI
npx tessl i tessl/pypi-py-solc-xevals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10