Skip to main content

Source code to structural graph facts — Python bindings

Project description

code2graph — Python bindings

Python bindings to the code2graph Rust library, which turns source files into structural facts: symbols (definitions), references (use sites), and cross-file edges.

Build

Inside a virtualenv, from the bindings/python directory:

pip install maturin
maturin develop

This compiles the Rust extension and installs it into the active virtualenv. The published distribution is named code2graph-rs (pip install code2graph-rs); the import name is code2graph.

Usage

import code2graph
facts = code2graph.extract("src/lib.rs", "pub fn hello() {}")
print(facts["symbols"])

extract(file, source) returns a dict mirroring the FileFacts schema (keys: symbols, references, scopes, bindings, ffi_exports). SymbolId values appear as their stable SCIP strings.

Resolve facts from multiple files into a cross-file graph with build_graph:

import code2graph
a = code2graph.extract("src/util.rs", "pub fn helper() {}")
b = code2graph.extract("src/main.rs", "pub fn run() { helper() }")
graph = code2graph.build_graph([a, b], tier="name")
print(graph["edges"])  # each edge: from, to, role, confidence, provenance, occ

build_graph(files, tier="name") returns a dict mirroring CodeGraph (symbols + edges). The tier argument selects the resolver: "name" (default, Tier A — fast, recall-first, NameOnly confidence) or "scope" (Tier B — scope-graph path resolution, Scoped/Exact confidence). The helper language_of(path) returns the canonical language tag for a path (e.g. "rust"), or None if the extension is unrecognized.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

code2graph_rs-0.0.0b3.tar.gz (366.5 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

code2graph_rs-0.0.0b3-cp39-abi3-win_amd64.whl (4.9 MB view details)

Uploaded CPython 3.9+Windows x86-64

code2graph_rs-0.0.0b3-cp39-abi3-musllinux_1_2_x86_64.whl (5.3 MB view details)

Uploaded CPython 3.9+musllinux: musl 1.2+ x86-64

code2graph_rs-0.0.0b3-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.1 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ x86-64

code2graph_rs-0.0.0b3-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (5.1 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

code2graph_rs-0.0.0b3-cp39-abi3-macosx_11_0_arm64.whl (5.1 MB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

code2graph_rs-0.0.0b3-cp39-abi3-macosx_10_12_x86_64.whl (5.0 MB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

Details for the file code2graph_rs-0.0.0b3.tar.gz.

File metadata

  • Download URL: code2graph_rs-0.0.0b3.tar.gz
  • Upload date:
  • Size: 366.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for code2graph_rs-0.0.0b3.tar.gz
Algorithm Hash digest
SHA256 89cd67a11d0f14e90eda319c62c3ea22e51fa6302fbfcc0243559ffcac66aeae
MD5 97c2d26674bf605c06d4dd5f49da5f4c
BLAKE2b-256 ab1973e4cc7492d5db8d8eb427c10fd46970bd7b895f8dd6d9bf02f3e4d99151

See more details on using hashes here.

Provenance

The following attestation bundles were made for code2graph_rs-0.0.0b3.tar.gz:

Publisher: release.yml on NodeDB-Lab/code2graph

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file code2graph_rs-0.0.0b3-cp39-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for code2graph_rs-0.0.0b3-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 f27afa24f26b25234904a245fd41253373a27dec95fee2d39bb716168e1bbbef
MD5 e9f95fc356289a54c54e89378857377d
BLAKE2b-256 c37d4f68a5418c2d13c5c8669af29b58ab10af0e82626a938eeeef8ecdd76b66

See more details on using hashes here.

Provenance

The following attestation bundles were made for code2graph_rs-0.0.0b3-cp39-abi3-win_amd64.whl:

Publisher: release.yml on NodeDB-Lab/code2graph

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file code2graph_rs-0.0.0b3-cp39-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for code2graph_rs-0.0.0b3-cp39-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 1c7f6752549ce9b49df654b7307968f783b55dba8efde68e99b194f7f6c57df3
MD5 df5f607f261fa0c1aea998b511c09dec
BLAKE2b-256 8c205d171d83ddc62699958b75496d7681c8021cb20b312c33938585f2f3e936

See more details on using hashes here.

Provenance

The following attestation bundles were made for code2graph_rs-0.0.0b3-cp39-abi3-musllinux_1_2_x86_64.whl:

Publisher: release.yml on NodeDB-Lab/code2graph

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file code2graph_rs-0.0.0b3-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for code2graph_rs-0.0.0b3-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 74f799786242c230482e936980e59fcad879da026e8650863af0dc49ab87c375
MD5 34a0b9bc10e68a18b8d48ed5982d3341
BLAKE2b-256 6a50b6233b726030dca4644793c6f808542025a99c3425c41f148f9c354cbdfd

See more details on using hashes here.

Provenance

The following attestation bundles were made for code2graph_rs-0.0.0b3-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on NodeDB-Lab/code2graph

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file code2graph_rs-0.0.0b3-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for code2graph_rs-0.0.0b3-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 b26c520864cb3554d82745345673f86731b97a68e6023320f7e01f95a2380fb7
MD5 1aac3b07976535b7f6e0a148b597e431
BLAKE2b-256 c829989b5ccb2ecb6f7596da709b9a0c5fcea0589b2045e054039170c5ca5ffd

See more details on using hashes here.

Provenance

The following attestation bundles were made for code2graph_rs-0.0.0b3-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on NodeDB-Lab/code2graph

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file code2graph_rs-0.0.0b3-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for code2graph_rs-0.0.0b3-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 34e4b7e787646d3e81673994fe3c7087aa666d7bf156b779a38c67777c32392c
MD5 af452b6b61f64be07379e0167c7bce0a
BLAKE2b-256 90369c522bbcedffcd539dbe1a61cb34eefb5a1d95aef3689c63fe019b82b454

See more details on using hashes here.

Provenance

The following attestation bundles were made for code2graph_rs-0.0.0b3-cp39-abi3-macosx_11_0_arm64.whl:

Publisher: release.yml on NodeDB-Lab/code2graph

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file code2graph_rs-0.0.0b3-cp39-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for code2graph_rs-0.0.0b3-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 360823071e86048b72aa6e242e8d7de0342f796c72556d748a951c08e9dbfd26
MD5 325ecdb955d2874594fb13bd032c8fab
BLAKE2b-256 9454a0a3001ba2b5cc30e03e1bc0df8f94fa9078abb217ef944950450081e62f

See more details on using hashes here.

Provenance

The following attestation bundles were made for code2graph_rs-0.0.0b3-cp39-abi3-macosx_10_12_x86_64.whl:

Publisher: release.yml on NodeDB-Lab/code2graph

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page