add python bindings with cython and pypi packaging support#27
Merged
MuriloChianfa merged 6 commits intomainfrom Jan 31, 2026
Merged
add python bindings with cython and pypi packaging support#27MuriloChianfa merged 6 commits intomainfrom
MuriloChianfa merged 6 commits intomainfrom
Conversation
* add php extension with pecl packaging support * fixing php binding test ci
Remove incorrect self-import in _liblpm.pyx that was causing compilation failure. Cython automatically imports the corresponding .pxd file, so explicit cimport _liblpm was creating a circular dependency. All references updated to use types/functions directly.
Welcome to Codecov 🎉Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests. ℹ️ You can also turn on project coverage checks and project coverage reporting on Pull Request comment Thanks for integrating Codecov - We've got you covered ☂️ |
MuriloChianfa
added a commit
that referenced
this pull request
Jan 31, 2026
Resolved conflicts in: - .github/workflows/ci.yml: Added Lua, Perl, PHP, and Python bindings tests - CMakeLists.txt: Combined Lua, Perl, PHP, and Python wrapper options - docker/README.md: Documented all language binding containers - scripts/docker-build.sh: Added support for all binding images This merge brings in the Perl (#28), Python (#27), and PHP (#26) bindings alongside the existing Lua bindings work.
MuriloChianfa
added a commit
that referenced
this pull request
Jan 31, 2026
Resolved conflicts in: - .github/workflows/ci.yml: Added C#, Lua, Perl, PHP, and Python bindings tests - CMakeLists.txt: Combined C#, Lua, Perl, PHP, and Python wrapper options - docker/README.md: Documented all language binding containers - scripts/docker-build.sh: Added support for all binding images This merge brings in the Lua (#29), Perl (#28), Python (#27), and PHP (#26) bindings alongside the existing C# bindings work.
MuriloChianfa
added a commit
that referenced
this pull request
Jan 31, 2026
Resolved conflicts in: - .github/workflows/ci.yml: Added Java, C#, Lua, Perl, PHP, and Python bindings tests - CMakeLists.txt: Combined Java, C#, Lua, Perl, PHP, and Python wrapper options - docker/README.md: Documented all language binding containers - scripts/docker-build.sh: Added support for all binding images This merge brings in the C# (#31), Lua (#29), Perl (#28), Python (#27), and PHP (#26) bindings alongside the existing Java bindings work.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR adds comprehensive Python bindings for the liblpm C library, enabling high-performance longest prefix match (LPM) routing table operations in Python applications. The bindings provide a Pythonic API with full type hints, context manager support, and minimal overhead through Cython.
Type of Change
Related Issues
Closes #
Motivation and Context
Python developers working with networking and routing need an efficient way to perform LPM lookups for both IPv4 and IPv6 addresses. While Python has powerful networking libraries, most LPM implementations in Python are either too slow (pure Python) or lack modern Pythonic APIs. This implementation bridges that gap by:
ipaddressmoduleChanges Made
Core Implementation
Cython bindings (
_liblpm.pyx,_liblpm.pxd): Low-level C wrapper with minimal overheadHigh-level API (
table.py): Pythonic interface usingipaddressmoduleLpmTableIPv4andLpmTableIPv6classesipaddressobject inputsException hierarchy (
exceptions.py):LpmError(base exception)LpmInsertError,LpmDeleteError,LpmClosedError,LpmInvalidPrefixErrorType hints (
.pyistub files): Full mypy support for IDE integrationBuild System
Modern packaging (
pyproject.toml): PEP 517/518 compliantCMake integration (
CMakeLists.txt): Seamless C library integrationManifest (
MANIFEST.in): Proper source distribution packagingTesting & Quality
Comprehensive test suite (4 test modules, 50+ tests):
test_ipv4.py: IPv4 operations and edge casestest_ipv6.py: IPv6 operations and edge casestest_batch.py: Batch lookup performance and correctnesstest_memory.py: Resource cleanup and memory safetyBenchmarks (
benchmarks/):Examples (
examples/):basic_example.py: Getting started guidebatch_lookup.py: Efficient batch operationscontext_manager.py: Resource management patternsalgorithms.py: Algorithm selection and comparisonDocumentation
Testing
Test Environment
Tests Performed
pytest tests/ -v)mypy src/liblpm/)Test Output
Performance Impact
Benchmark Results
Python bindings achieve near-native C performance:
Batch operations provide significant performance gains:
Documentation
Code Quality
Quality checks:
Breaking Changes
This is a new feature addition with no impact on existing C library or other language bindings.
Additional Notes
Key Features
ipaddressmodule types for seamless integration.pyistub filesPackage Structure
Files Changed
PyPI Publishing
Package is ready for PyPI distribution:
pyproject.tomlconfigurationMANIFEST.inChecklist
Reviewer Notes
Areas for Review
Testing Instructions
Future Enhancements (Out of Scope)
nogilcontains(),prefixes())