Skip to main content

Stack-Graphs Python bindings

Opinionated Python bindings for the tree-sitter-stack-graphs rust library.

It exposes a minimal, opinionated API to leverage the stack-graphs library for reference resolution in source code.

The rust bindings are built using PyO3 and maturin.

Note that this is a work in progress, and the API is subject to change. This project is not affiliated with GitHub.

Installation & Usage

pip install stack-graphs-python-bindings

Example

Given the following directory structure:

tests/js_sample
├── index.js
└── module.js

index.js:

import { foo } from "./module"
const baz = foo

module.js:

export const foo = "bar"

The following Python script:

import os
from stack_graphs_python import Indexer, Querier, Position, Language

db_path = os.path.abspath("./db.sqlite")
dir = os.path.abspath("./tests/js_sample")

# Index the directory (creates stack-graphs database)
indexer = Indexer(db_path, [Language.JavaScript])
indexer.index_all([dir])

# Instantiate a querier
querier = Querier(db_path)

# Query a reference at a given position (0-indexed line and column):
# foo in: const baz = foo
source_reference = Position(path=dir + "/index.js", line=2, column=12)
results = querier.definitions(source_reference)

for r in results:
    print(r)

Will output:

Position(path="[...]/tests/js_sample/index.js", line=0, column=9)
Position(path="[...]/tests/js_sample/module.js", line=0, column=13)

That translates to:

// index.js
import { foo } from "./module"
      // ^ line 0, column 9

// module.js
export const foo = "bar"
          // ^ line 0, column 13

Note: All the paths are absolute, and line and column numbers are 0-indexed (first line is 0, first column is 0).

Known stack-graphs / tree-sitter issues

Development

Ressources

https://pyo3.rs/v0.21.2/getting-started

Requirements

  • Rust
  • Python 3.12+

Setup

# Setup venv and install dev dependencies
make setup

Testing

make test

Manual testing

# build the package
make develop
# activate the venv
. venv/bin/activate

Roadmap

Before releasing 0.1.0, which I expect to be a first stable API, the following needs to be done:

  • Add more testing, especially:
    • Test all supported languages (Java, Python, TypeScript, JavaScript)
    • Test failing cases, eg. files that cannot be indexed
  • Add options to the classes:
    • Verbosity
    • Force for the Indexer
    • Fail on error for the Indexer, or continue indexing
  • Handle the storage (database) in a dedicated class, and pass it to the Indexer and Querier -> this might not be necessary
  • Add methods to query the indexing status (eg. which files have been indexed, which failed, etc.)
  • Rely on the main branch of stack-graphs, and update the bindings accordingly
  • Better error handling, return clear errors, test them and add them to the .pyi interface
  • Lint and format the rust code
  • CI/CD for the rust code
  • Lint and format the python code
  • Propper changelog, starting in 0.1.0

I'd also like to add the following features, after 0.1.0:

  • Expose the exact, lower-level API of stack-graphs, for more flexibility, in a separate module (eg. stack_graphs_python.core)
  • Benchmark performance

Release files for stack-graphs-python-bindings 0.0.14

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for stack-graphs-python-bindings 0.0.14
File Size Uploaded
stack_graphs_python_bindings-0.0.14.tar.gz 30.4 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for stack-graphs-python-bindings 0.0.14
File
stack_graphs_python_bindings-0.0.14-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.13 CPython 3.13 free-threading Linux glibc 2.17+ ARM64 Details
stack_graphs_python_bindings-0.0.14-cp313-cp313-win32.whl CPython 3.13 CPython 3.13 Windows x86-32 Details
stack_graphs_python_bindings-0.0.14-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.17+ x86-64 Details
stack_graphs_python_bindings-0.0.14-cp313-cp313-manylinux_2_17_i686.manylinux2014_i686.whl CPython 3.13 CPython 3.13 Linux glibc 2.17+ x86-32 Details
stack_graphs_python_bindings-0.0.14-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.13 CPython 3.13 Linux glibc 2.17+ ARM64 Details
stack_graphs_python_bindings-0.0.14-cp313-cp313-macosx_11_0_arm64.whl CPython 3.13 CPython 3.13 macOS 11.0+ ARM64 Details
stack_graphs_python_bindings-0.0.14-cp313-cp313-macosx_10_12_x86_64.whl CPython 3.13 CPython 3.13 macOS 10.12+ x86-64 Details
stack_graphs_python_bindings-0.0.14-cp312-cp312-win32.whl CPython 3.12 CPython 3.12 Windows x86-32 Details
stack_graphs_python_bindings-0.0.14-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.17+ x86-64 Details
stack_graphs_python_bindings-0.0.14-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl CPython 3.12 CPython 3.12 Linux glibc 2.17+ x86-32 Details
stack_graphs_python_bindings-0.0.14-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.12 CPython 3.12 Linux glibc 2.17+ ARM64 Details
stack_graphs_python_bindings-0.0.14-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details
stack_graphs_python_bindings-0.0.14-cp312-cp312-macosx_10_12_x86_64.whl CPython 3.12 CPython 3.12 macOS 10.12+ x86-64 Details

Total release size: 45.6 MB

Release files / stack_graphs_python_bindings-0.0.14.tar.gz

Download URL stack_graphs_python_bindings-0.0.14.tar.gz
Size 30.4 kB
Tags Source
SHA-256 checksum
How to use checksums
31bdf5552ab6835ff0860775e162f0a2c52c2d63e2868b1ef9c67420ad010355
BLAKE2b-256 checksum
How to use checksums
65efda5de9536ae9f7898df5c8176e511b534faca699d9afebe6e6d6344da78a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.8.3

Release files / stack_graphs_python_bindings-0.0.14-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL stack_graphs_python_bindings-0.0.14-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 3.2 MB
Tags CPython 3.13 CPython 3.13 free-threading Linux glibc 2.17+ ARM64
SHA-256 checksum
How to use checksums
2819ec2489aff5cb43127aedaed8d3c18808c329ccdf8a3187372341a938a793
BLAKE2b-256 checksum
How to use checksums
1769baab7f4ed1a8baf8377a70997e1fec1bf111222461cf71b16c76330cf4f0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.8.3

Release files / stack_graphs_python_bindings-0.0.14-cp313-cp313-win32.whl

Download URL stack_graphs_python_bindings-0.0.14-cp313-cp313-win32.whl
Size 3.0 MB
Tags CPython 3.13 Windows x86-32
SHA-256 checksum
How to use checksums
ab9cb4d175836a4ec2e4519ba7afc70177c8cfbc7c5d213370a65c188bf60eda
BLAKE2b-256 checksum
How to use checksums
ee1002ddbdf50b6b85ddc03991584e608a95f5ad7ce8b193aa07e7d82728cb4e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.8.3

Release files / stack_graphs_python_bindings-0.0.14-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL stack_graphs_python_bindings-0.0.14-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 3.9 MB
Tags CPython 3.13 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
8fcc6a4a2bed8944fb2f31d889d62e5bae7ba696909aeefb8348cfd4ee2f673a
BLAKE2b-256 checksum
How to use checksums
d181b4d532f061785e60d4acf97dc03159abe42485481aa662634f9ebd32fc40
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.8.3

Release files / stack_graphs_python_bindings-0.0.14-cp313-cp313-manylinux_2_17_i686.manylinux2014_i686.whl

Download URL stack_graphs_python_bindings-0.0.14-cp313-cp313-manylinux_2_17_i686.manylinux2014_i686.whl
Size 4.0 MB
Tags CPython 3.13 Linux glibc 2.17+ x86-32
SHA-256 checksum
How to use checksums
8b435bda8ff6cd6eba14c563cc0e045a20393415d4468fa8870f372de2c034d2
BLAKE2b-256 checksum
How to use checksums
f7f2e063f21525c85de401f11ccb02158d6197aa8670298a3de26c9a3743fc08
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.8.3

Release files / stack_graphs_python_bindings-0.0.14-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL stack_graphs_python_bindings-0.0.14-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 3.2 MB
Tags CPython 3.13 Linux glibc 2.17+ ARM64
SHA-256 checksum
How to use checksums
c60d921549609a2e2bbb80bbadae432552502af1c7e720790182d2b945901573
BLAKE2b-256 checksum
How to use checksums
f6d20eef216ff3c237d258e393a2e2e375a986be5dd364be5b8eead0437cab4b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.8.3

Release files / stack_graphs_python_bindings-0.0.14-cp313-cp313-macosx_11_0_arm64.whl

Download URL stack_graphs_python_bindings-0.0.14-cp313-cp313-macosx_11_0_arm64.whl
Size 3.4 MB
Tags CPython 3.13 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
9a33fc075b234a7c4475724f8826098c1355502a5c2ebe28709b68d5c93153ca
BLAKE2b-256 checksum
How to use checksums
4bec45a1036164a2fc689cae8f6bf08ee76b466fd333bcba983a71d118dc6e4d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.8.3

Release files / stack_graphs_python_bindings-0.0.14-cp313-cp313-macosx_10_12_x86_64.whl

Download URL stack_graphs_python_bindings-0.0.14-cp313-cp313-macosx_10_12_x86_64.whl
Size 3.6 MB
Tags CPython 3.13 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
760e9351d5c46d1da94c4d989ade571a279a03a4972477d00768893346265ec4
BLAKE2b-256 checksum
How to use checksums
a3fc94027b1f28fd49e39a00ed3b9310c768aa026d4e9c906e48a540ad1a8016
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.8.3

Release files / stack_graphs_python_bindings-0.0.14-cp312-cp312-win32.whl

Download URL stack_graphs_python_bindings-0.0.14-cp312-cp312-win32.whl
Size 3.0 MB
Tags CPython 3.12 Windows x86-32
SHA-256 checksum
How to use checksums
de8ec4ed5c4611cc43489b4b3c9f4b70e1381dad93d50416a434ac7ea691849f
BLAKE2b-256 checksum
How to use checksums
c0914f1013dc7f714ff5a46c61907053f624200fdc501144c1c8b69c8adb3dd4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.8.3

Release files / stack_graphs_python_bindings-0.0.14-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL stack_graphs_python_bindings-0.0.14-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 3.9 MB
Tags CPython 3.12 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
1572d954b670fb3668f0eb6e2284d830ec97fca69a54feb45832152dcf9f5562
BLAKE2b-256 checksum
How to use checksums
23be62e706ea3ef83b3b01beb05e314a19e20bc882a599468d5f8b3374033625
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.8.3

Release files / stack_graphs_python_bindings-0.0.14-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl

Download URL stack_graphs_python_bindings-0.0.14-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl
Size 4.0 MB
Tags CPython 3.12 Linux glibc 2.17+ x86-32
SHA-256 checksum
How to use checksums
c0397a24771a5dd8cd9440db9a81a20349295edebadb7563801a3c4170e20e9a
BLAKE2b-256 checksum
How to use checksums
9b1f7f69bca5488656900feb442f2cd78f425c774a90d4bff378e3d4341942e2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.8.3

Release files / stack_graphs_python_bindings-0.0.14-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL stack_graphs_python_bindings-0.0.14-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 3.2 MB
Tags CPython 3.12 Linux glibc 2.17+ ARM64
SHA-256 checksum
How to use checksums
da9b0c760a63066b18b9bf4cb0582ecf1310aa5ec537c5dbb3875048ad18fe87
BLAKE2b-256 checksum
How to use checksums
aa6790def0e77cbd62daa4d75ef52c96d3776c7494a151983e6e2d094d7eedcc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.8.3

Release files / stack_graphs_python_bindings-0.0.14-cp312-cp312-macosx_11_0_arm64.whl

Download URL stack_graphs_python_bindings-0.0.14-cp312-cp312-macosx_11_0_arm64.whl
Size 3.4 MB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
63ae76e66ad64e7d28c54c2fa9db9c48cf19393d7122cb9eeadbfa646ff984b3
BLAKE2b-256 checksum
How to use checksums
b957f4edabcdb7f8c55506561ff188cad5d89a3cfa4680531b19c09eb49a3fa6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.8.3

Release files / stack_graphs_python_bindings-0.0.14-cp312-cp312-macosx_10_12_x86_64.whl

Download URL stack_graphs_python_bindings-0.0.14-cp312-cp312-macosx_10_12_x86_64.whl
Size 3.6 MB
Tags CPython 3.12 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
46d7675560b731155e86b6ca9b87ac257d8852ef62ab949f73f790a6c7585b5b
BLAKE2b-256 checksum
How to use checksums
6d1547a8d7304038e9add45e72a6c6dec09ced6eff505880d1ce12656f65f3d2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.8.3

Release history Release notifications | RSS feed

This release

0.0.14 This release

14 release files

0.0.9

13 release files

0.0.8

13 release files

0.0.7

13 release files

0.0.6

13 release files

0.0.5

13 release files

0.0.4

13 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page