Python bindings for Ranex - exposes Atlas codebase indexing to Python
Project description
ranex-py
Python bindings for the Ranex Atlas codebase indexing system.
Overview
This crate exposes the Rust-powered Atlas scanner, parser, and storage to Python via PyO3, enabling Python users to index and search their codebases efficiently.
Architecture
┌─────────────────────────────────────────────────────┐
│ Python Code │
│ from ranex_rust import Atlas │
│ atlas = Atlas(".") │
│ atlas.scan() │
│ results = atlas.search("payment") │
└───────────────────────┬─────────────────────────────┘
│ FFI Boundary (PyO3)
▼
┌─────────────────────────────────────────────────────┐
│ ranex-py (ranex_rust.so) │
│ • PyAtlas: Main Python class │
│ • Type conversions: Rust → Python dicts │
│ • Error handling: Rust errors → Python exceptions│
└───────────────────────┬─────────────────────────────┘
│ Calls
▼
┌─────────────────────────────────────────────────────┐
│ ranex-atlas + ranex-core (Rust) │
│ • Scanner, Parser, Storage │
└─────────────────────────────────────────────────────┘
Python API
Atlas Class
from ranex_rust import Atlas
# Initialize for a project
atlas = Atlas("/path/to/project")
# Scan and index the codebase
result = atlas.scan()
print(f"Found {result['artifacts_found']} artifacts in {result['duration_ms']}ms")
# Search for symbols
results = atlas.search("payment", limit=10)
for artifact in results:
print(f" {artifact['symbol_name']} ({artifact['kind']}) - {artifact['file_path']}")
# Search by feature
payment_artifacts = atlas.search_by_feature("payment")
# Get artifact count
count = atlas.count()
# Health check
health = atlas.health()
print(f"Status: {health['status']}, Artifacts: {health['artifact_count']}")
ArtifactKind Constants
from ranex_rust import ArtifactKind
# Available kinds:
ArtifactKind.FUNCTION # "function"
ArtifactKind.ASYNC_FUNCTION # "async_function"
ArtifactKind.CLASS # "class"
ArtifactKind.METHOD # "method"
ArtifactKind.ENDPOINT # "endpoint" (FastAPI routes)
ArtifactKind.CONTRACT # "contract" (@Contract decorated)
ArtifactKind.MODEL # "model" (Pydantic models)
ArtifactKind.CONSTANT # "constant"
Utility Functions
from ranex_rust import version, init_logging
# Get version
print(version()) # "0.1.0"
# Initialize logging
init_logging("debug") # "trace", "debug", "info", "warn", "error"
Return Types
atlas.scan() → dict
{
"artifacts_found": 1234,
"files_scanned": 156,
"files_parsed": 154,
"files_failed": 2,
"duration_ms": 3200,
"stats": {
"files_scanned": 156,
"files_parsed": 154,
"files_failed": 2,
"files_skipped": 0,
"files_cached": 0,
"artifacts_found": 1234,
"artifacts_by_kind": {
"function": 800,
"class": 200,
"endpoint": 150,
...
}
},
"failed_files": [
{"path": "bad_syntax.py", "error": "SyntaxError: ..."}
]
}
atlas.search() → list[dict]
[
{
"symbol_name": "process_payment",
"qualified_name": "app.services.payment.process_payment",
"kind": "function",
"file_path": "app/services/payment.py",
"module_path": "app.services.payment",
"line_start": 45,
"line_end": 78,
"signature": "process_payment(request: PaymentRequest) -> PaymentResponse",
"docstring": "Process a payment with fraud checks.",
"feature": "payment",
"tags": ["business_logic"],
"hash": "abc123..."
},
...
]
atlas.health() → dict
{
"artifact_count": 1234,
"last_scan": 1704067200, # Unix timestamp, or None
"db_path": "/project/.ranex/atlas.sqlite",
"status": "healthy" # or "needs_scan"
}
Error Handling
The module raises appropriate Python exceptions:
from ranex_rust import Atlas
try:
atlas = Atlas("/nonexistent/path")
except FileNotFoundError as e:
print(f"Project not found: {e}")
try:
atlas.scan()
except RuntimeError as e:
print(f"Scan failed: {e}")
except IOError as e:
print(f"I/O error: {e}")
Building
Development Build
cd ranex-rs
maturin develop -m crates/ranex-py/Cargo.toml
Release Build
maturin build --release -m crates/ranex-py/Cargo.toml
Wheel Distribution
maturin build --release --strip -m crates/ranex-py/Cargo.toml
# Output: target/wheels/ranex_rust-*.whl
Testing
# Run Rust tests
cargo test -p ranex-py
# Run with Python (after maturin develop)
python -c "from ranex_rust import Atlas; print(Atlas)"
Module Structure
ranex-py/
├── src/
│ ├── lib.rs # PyModule definition, PyAtlas class
│ ├── error.rs # PyAtlasError, error conversions
│ └── types.rs # Rust → Python type conversions
├── tests/
│ ├── common/
│ │ └── mod.rs # Shared test utilities
│ ├── atlas_tests.rs
│ ├── error_tests.rs
│ └── types_tests.rs
├── Cargo.toml
└── README.md
Features
abi3: Build with Python stable ABI (works across Python 3.8+)
cargo build -p ranex-py --features abi3
Performance
- GIL Release: Long operations (scan, search) do not release the GIL
- Zero-Copy: Where possible, strings are borrowed rather than copied
- Batch Conversions: Lists of artifacts are converted efficiently
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ranex-0.1.3.tar.gz.
File metadata
- Download URL: ranex-0.1.3.tar.gz
- Upload date:
- Size: 231.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c0ed02e1882575a6c4a2a530bc071e94ca9334c32620e2682d43c956b76b8de6
|
|
| MD5 |
08a51f6e2980d26b1e0526530d601010
|
|
| BLAKE2b-256 |
230f9430b87f0847bd0ac9e6620e45e88534c5333fb36589e4191acc348d3ebd
|
Provenance
The following attestation bundles were made for ranex-0.1.3.tar.gz:
Publisher:
release.yml on anthonykewl20/ranex-core
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ranex-0.1.3.tar.gz -
Subject digest:
c0ed02e1882575a6c4a2a530bc071e94ca9334c32620e2682d43c956b76b8de6 - Sigstore transparency entry: 772102204
- Sigstore integration time:
-
Permalink:
anthonykewl20/ranex-core@5c2699271af8877fca29c4b14081ab4e42fbe788 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/anthonykewl20
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@5c2699271af8877fca29c4b14081ab4e42fbe788 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file ranex-0.1.3-cp311-cp311-win_amd64.whl.
File metadata
- Download URL: ranex-0.1.3-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 2.6 MB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c174f9353bcd000e49ddd214500331acb05a3223e61a519233c8b48fa87952a6
|
|
| MD5 |
70e8bbf79f5200586e781a0e68e7c0f0
|
|
| BLAKE2b-256 |
a1c656844f770e029b9f7ffdce66f3c39d74fb15958f8b82c4f10a5fe0d49549
|
Provenance
The following attestation bundles were made for ranex-0.1.3-cp311-cp311-win_amd64.whl:
Publisher:
release.yml on anthonykewl20/ranex-core
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ranex-0.1.3-cp311-cp311-win_amd64.whl -
Subject digest:
c174f9353bcd000e49ddd214500331acb05a3223e61a519233c8b48fa87952a6 - Sigstore transparency entry: 772102243
- Sigstore integration time:
-
Permalink:
anthonykewl20/ranex-core@5c2699271af8877fca29c4b14081ab4e42fbe788 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/anthonykewl20
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@5c2699271af8877fca29c4b14081ab4e42fbe788 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file ranex-0.1.3-cp311-cp311-manylinux_2_39_x86_64.whl.
File metadata
- Download URL: ranex-0.1.3-cp311-cp311-manylinux_2_39_x86_64.whl
- Upload date:
- Size: 2.9 MB
- Tags: CPython 3.11, manylinux: glibc 2.39+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dd1eb4b584448a737993e09bf1c9dedfaa94acf7971d67e5c219fc013d6e618b
|
|
| MD5 |
62452fe9e28b3025e298dc6f96445c92
|
|
| BLAKE2b-256 |
2805167b19a91f2804b767c999e56ab53956aed7fada654bcfe5c83255e1dbca
|
Provenance
The following attestation bundles were made for ranex-0.1.3-cp311-cp311-manylinux_2_39_x86_64.whl:
Publisher:
release.yml on anthonykewl20/ranex-core
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ranex-0.1.3-cp311-cp311-manylinux_2_39_x86_64.whl -
Subject digest:
dd1eb4b584448a737993e09bf1c9dedfaa94acf7971d67e5c219fc013d6e618b - Sigstore transparency entry: 772102225
- Sigstore integration time:
-
Permalink:
anthonykewl20/ranex-core@5c2699271af8877fca29c4b14081ab4e42fbe788 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/anthonykewl20
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@5c2699271af8877fca29c4b14081ab4e42fbe788 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file ranex-0.1.3-cp311-cp311-macosx_11_0_arm64.whl.
File metadata
- Download URL: ranex-0.1.3-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 2.5 MB
- Tags: CPython 3.11, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
954ba42deecb8f062e79f09f35459b6e2f1779ffeb8b9a94f3010d945f9ff559
|
|
| MD5 |
e19b7875f729f345a3e5578780542db0
|
|
| BLAKE2b-256 |
97ca564bb944724e008531bce258f9d327e1312676b9f5e46e4eff0590234028
|
Provenance
The following attestation bundles were made for ranex-0.1.3-cp311-cp311-macosx_11_0_arm64.whl:
Publisher:
release.yml on anthonykewl20/ranex-core
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ranex-0.1.3-cp311-cp311-macosx_11_0_arm64.whl -
Subject digest:
954ba42deecb8f062e79f09f35459b6e2f1779ffeb8b9a94f3010d945f9ff559 - Sigstore transparency entry: 772102250
- Sigstore integration time:
-
Permalink:
anthonykewl20/ranex-core@5c2699271af8877fca29c4b14081ab4e42fbe788 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/anthonykewl20
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@5c2699271af8877fca29c4b14081ab4e42fbe788 -
Trigger Event:
workflow_dispatch
-
Statement type: