Solc-Parser
A powerful Solidity compiler (solc) version management tool that automatically parses Solidity files and installs the appropriate solc version based on pragma statements and version requirements.
Features
- Automatic Version Detection: Parses Solidity files to extract version requirements from pragma statements
- Complete npm Semver Support: Full implementation of npm semantic versioning rules including:
- Caret ranges (
^1.2.3) - Tilde ranges (
~1.2.3) - Hyphen ranges (
1.2.3 - 2.3.4) - X-ranges (
1.2.x,1.x,*,0.8.*) - Comparison operators (
>=,<=,>,<,=) - Logical OR (
||) - Prerelease tags (
1.2.3-alpha.1) - Build metadata (
1.2.3+build.1)
- Caret ranges (
- Advanced Pragma Support: Parses and handles:
pragma solidityversion rangespragma abicoder v1/v2pragma experimental ABIEncoderV2, SMTChecker
- Automatic Installation: Downloads and installs solc binaries from official sources
- Global Version Management: Creates symbolic links for easy version switching
- Cross-Platform Support: Works on Linux and macOS
- PATH Integration: Provides instructions for PATH setup
Installation
From Source
git clone https://github.com/siksum/Solc-Parser.git
cd Solc-Parser
pip install -e .
Using pip
pip install solc-parser
Usage
Basic Usage
Parse a Solidity file and automatically install the appropriate solc version:
solc-parser your_contract.sol
Command Line Options
# List all available solc versions
solc-parser --list
# Install specific version(s)
solc-parser --install 0.8.30
solc-parser --install 0.7.* # Install latest 0.7.x version
# Use specific version
solc-parser --use 0.8.30
solc-parser --use 0.7.* # Use latest 0.7.x version
# Uninstall version(s)
solc-parser --uninstall 0.7.6
# Show current version
solc-parser --version
Examples
Simple Solidity File
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract SimpleContract {
uint256 public value;
function setValue(uint256 _value) external {
value = _value;
}
}
Running solc-parser simple.sol will:
- Parse the pragma statement
^0.8.0 - Find the latest compatible version (e.g., 0.8.30)
- Download and install solc 0.8.30
- Create a symbolic link for global use
Advanced Solidity File with Multiple Pragmas
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
pragma abicoder v2;
pragma experimental SMTChecker;
contract AdvancedContract {
struct ComplexStruct {
uint256[] numbers;
string name;
}
function processData(ComplexStruct memory data) external pure returns (uint256) {
return data.numbers.length;
}
}
Running solc-parser advanced.sol will:
- Parse all pragma statements
- Determine version requirements:
^0.8.0(solidity version)>=0.5.0(abicoder v2 requirement)>=0.5.0(SMTChecker requirement)
- Find the best matching version that satisfies all requirements
- Install and configure the appropriate solc version
Version Range Support
Caret Ranges (^)
^1.2.3:=>=1.2.3 <2.0.0^0.2.3:=>=0.2.3 <0.3.0^0.0.3:=>=0.0.3 <0.1.0
Tilde Ranges (~)
~1.2.3:=>=1.2.3 <1.3.0~1.2:=>=1.2.0 <1.3.0~1:=>=1.0.0 <2.0.0
X-Ranges
1.2.xor1.2.*:=>=1.2.0 <1.3.01.xor1.*:=>=1.0.0 <2.0.0*orx:= accepts all versions
Hyphen Ranges
1.2.3 - 2.3.4:=>=1.2.3 <=2.3.4
Comparison Operators
>=1.2.3,<=1.2.3,>1.2.3,<1.2.3,=1.2.3
Logical OR
^1.2.3 || ^2.3.4:= satisfies either range
Installation Directory
Solc binaries are installed in:
~/.solc-parser/bin/
├── solc-0.7.6/
│ └── solc
├── solc-0.8.30/
│ └── solc
└── solc -> solc-0.8.30/solc # Symbolic link to current version
PATH Setup
After installation, add the binary directory to your PATH:
Temporary (current session only)
export PATH="$HOME/.solc-parser/bin:$PATH"
Permanent (bash)
echo 'export PATH="$HOME/.solc-parser/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
Permanent (zsh)
echo 'export PATH="$HOME/.solc-parser/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
Alternative: Use alias
echo "alias solc='$HOME/.solc-parser/bin/solc'" >> ~/.bashrc
source ~/.bashrc
Requirements
- Python 3.8 or higher
- Linux or macOS
- Internet connection for downloading solc binaries
Dependencies
requests: For downloading solc binaries
Development
Building
./build.sh
Testing
python -m pytest tests/
License
This project is licensed under the GNU General Public License v3 (GPLv3) - see the LICENSE file for details.
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
Issues
If you encounter any issues, please report them on the GitHub Issues page.
Author
Namryeong Kim - GitHub
Acknowledgments
- Solidity team for the official solc binaries
- npm semver specification for version range parsing rules
Metadata
Release files for solc-parser 1.1.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 |
|---|---|---|---|---|
| solc_parser-1.1.0.tar.gz | 23.4 kB | Without provenance | Details for solc_parser-1.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| solc_parser-1.1.0-py3-none-any.whl | Python 3 | none | any | Details for solc_parser-1.1.0-py3-none-any.whl |
Total release size: 47.8 kB
Release files / solc_parser-1.1.0.tar.gz
| Download URL | solc_parser-1.1.0.tar.gz |
|---|---|
| Size | 23.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9319885605744d5f4866d349ba821f471a6aa6c8164c069be2734831e5a50ceb
|
|
BLAKE2b-256 checksum How to use checksums |
8854d8e8084bb6dfd422616505b25f9886958f16e7a3ffd31a45839b0aa84655
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.3
|
Release files / solc_parser-1.1.0-py3-none-any.whl
| Download URL | solc_parser-1.1.0-py3-none-any.whl |
|---|---|
| Size | 24.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
704f2a0487324ca2589754267c96f20355093efc61bcec577d6a42af5a5d3555
|
|
BLAKE2b-256 checksum How to use checksums |
722a36c38fe92e4065110c46a35b1440010cf1765b42e5b6d499fad84528a401
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.3
|
Security for solc-parser 1.1.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.