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.0b4.tar.gz (366.6 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.0b4-cp39-abi3-win_amd64.whl (4.9 MB view details)

Uploaded CPython 3.9+Windows x86-64

code2graph_rs-0.0.0b4-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.0b4-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.0b4-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.0b4-cp39-abi3-macosx_11_0_arm64.whl (5.1 MB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

code2graph_rs-0.0.0b4-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.0b4.tar.gz.

File metadata

  • Download URL: code2graph_rs-0.0.0b4.tar.gz
  • Upload date:
  • Size: 366.6 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.0b4.tar.gz
Algorithm Hash digest
SHA256 0fd4861b9c1e85721fdc0a4c7eb0ab961511f6647aade05b6641e16deff326cd
MD5 5e425325e906f8f8ad34c60a307b94ef
BLAKE2b-256 7a75ea5d898e0b9f93698ae1694ff779c0e197514fc178a633e737b29fc2172a

See more details on using hashes here.

Provenance

The following attestation bundles were made for code2graph_rs-0.0.0b4.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.0b4-cp39-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for code2graph_rs-0.0.0b4-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 26803489639f49abcb00f08a41307a40b3df0bae86e40d5acb6e5121ff394c99
MD5 a9489e10acebb38087a92c9783ea9c3a
BLAKE2b-256 31568c010c3573093d3239c8d59f4f0ee6ddf6d00e67925b46b1169eafb1f201

See more details on using hashes here.

Provenance

The following attestation bundles were made for code2graph_rs-0.0.0b4-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.0b4-cp39-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for code2graph_rs-0.0.0b4-cp39-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 159fc1be130790ffae35ffe7683fdee9910b9147531aa3c1127c6d40b7741127
MD5 b07019f31c383b558e4362aa83d3da9b
BLAKE2b-256 4755161e6685546da2fb3365ea610c465e53ac3f82c738cbef93710a8d16dde4

See more details on using hashes here.

Provenance

The following attestation bundles were made for code2graph_rs-0.0.0b4-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.0b4-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for code2graph_rs-0.0.0b4-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 17132e14f54ccf0c613091c1ddbeaf2636292a6c1804af199926f16fb4f21ee0
MD5 3a25f1b9b6436aaff8fda03a690e3af4
BLAKE2b-256 38dda29551f482de14d571798c702549d8225429f727a1a64cdca803fc7f2512

See more details on using hashes here.

Provenance

The following attestation bundles were made for code2graph_rs-0.0.0b4-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.0b4-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for code2graph_rs-0.0.0b4-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 c756d26b3fc6f1c2f02eb3fc70bfde1e56d9a2e3015aacd8015d372757bcf260
MD5 a8d136352328f419b38ab432faf0bcc1
BLAKE2b-256 3296b76dea637dde95e5342266993f08574a107bdddb8964d95f1adef1679bbb

See more details on using hashes here.

Provenance

The following attestation bundles were made for code2graph_rs-0.0.0b4-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.0b4-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for code2graph_rs-0.0.0b4-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 142fe5fc30cb445a9057a7eb0ff2f518577e4c100d6a0fc215e96aca4b58e418
MD5 e12e730ff6589d1c037761855c8ce46a
BLAKE2b-256 4f4d249fa8913925b0a47aac35e98a4f97ecd99666a360c79b4ee7e387e7f875

See more details on using hashes here.

Provenance

The following attestation bundles were made for code2graph_rs-0.0.0b4-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.0b4-cp39-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for code2graph_rs-0.0.0b4-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 98f31aae98a87e8fea774ff8cc96f0f37e3328a24c48d6e8444e5ac243ddb193
MD5 48c5c43e025d75c7366164313031fbf5
BLAKE2b-256 a5320c344e3277bc1894c6bba5faa65c8927dedd35f6ace81b560e705b3f84f5

See more details on using hashes here.

Provenance

The following attestation bundles were made for code2graph_rs-0.0.0b4-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