PHP-compatible version comparison for Python
APACHE-2.0 License
ℹ️ Note: This project is feature-complete and will only receive updates for bug fixes or compatibility with new Python versions. No new features are planned. If you require additional features, please consider forking the project.
A simple Python library for comparing version strings in a manner compatible with PHP's version_compare function. Although this implementation is not derived from PHP's code, it passes the same tests to ensure compatibility.
To install php-version-compare
, use pip:
pip install php-version-compare
The complete documentation can be found on Read the Docs.
from php_version_compare import version_compare
# Without operator
print(version_compare('1.0', '1.1')) # Output: -1
print(version_compare('1.1', '1.0')) # Output: 1
print(version_compare('1.0', '1.0')) # Output: 0
# With operator
print(version_compare('1.1', '1.0.0', operator='>=')) # Output: True
print(version_compare('1.0.0', '1.1', operator='<=')) # Output: True
print(version_compare('1.0', '1.0', operator='!=')) # Output: False
git checkout -b feature-branch
).git commit -m 'Add new feature'
).git push origin feature-branch
).To run tests, make sure you have tox
installed and run the following command, which will run the tests for all
supported Python versions that are installed on your system:
tox
If you only want to run the tests for a specific Python version, you can specify the version:
tox -e py39
This project is licensed under either of the following, at your option:
Which license to use is up to you. This project is dual-licensed for compatibility with both. When contributing, you agree to license your contributions under the same terms.
This project uses Semantic Versioning. For the versions available, see the tags on this repository or the releases page.