Skip to main content

No project description provided

Project description

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

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

stack_graphs_python_bindings-0.0.14.tar.gz (30.4 kB view details)

Uploaded Source

Built Distributions

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

stack_graphs_python_bindings-0.0.14-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (3.2 MB view details)

Uploaded CPython 3.13tmanylinux: glibc 2.17+ ARM64

stack_graphs_python_bindings-0.0.14-cp313-cp313-win32.whl (3.0 MB view details)

Uploaded CPython 3.13Windows x86

stack_graphs_python_bindings-0.0.14-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.9 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

stack_graphs_python_bindings-0.0.14-cp313-cp313-manylinux_2_17_i686.manylinux2014_i686.whl (4.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ i686

stack_graphs_python_bindings-0.0.14-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (3.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

stack_graphs_python_bindings-0.0.14-cp313-cp313-macosx_11_0_arm64.whl (3.4 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

stack_graphs_python_bindings-0.0.14-cp313-cp313-macosx_10_12_x86_64.whl (3.6 MB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

stack_graphs_python_bindings-0.0.14-cp312-cp312-win32.whl (3.0 MB view details)

Uploaded CPython 3.12Windows x86

stack_graphs_python_bindings-0.0.14-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.9 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

stack_graphs_python_bindings-0.0.14-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl (4.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ i686

stack_graphs_python_bindings-0.0.14-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (3.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

stack_graphs_python_bindings-0.0.14-cp312-cp312-macosx_11_0_arm64.whl (3.4 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

stack_graphs_python_bindings-0.0.14-cp312-cp312-macosx_10_12_x86_64.whl (3.6 MB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

File details

Details for the file stack_graphs_python_bindings-0.0.14.tar.gz.

File metadata

File hashes

Hashes for stack_graphs_python_bindings-0.0.14.tar.gz
Algorithm Hash digest
SHA256 31bdf5552ab6835ff0860775e162f0a2c52c2d63e2868b1ef9c67420ad010355
MD5 b1106121aa90e62303dd748ece554676
BLAKE2b-256 65efda5de9536ae9f7898df5c8176e511b534faca699d9afebe6e6d6344da78a

See more details on using hashes here.

File details

Details for the file stack_graphs_python_bindings-0.0.14-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for stack_graphs_python_bindings-0.0.14-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 2819ec2489aff5cb43127aedaed8d3c18808c329ccdf8a3187372341a938a793
MD5 3a4f8f003772fa2d5e070617eed82ab6
BLAKE2b-256 1769baab7f4ed1a8baf8377a70997e1fec1bf111222461cf71b16c76330cf4f0

See more details on using hashes here.

File details

Details for the file stack_graphs_python_bindings-0.0.14-cp313-cp313-win32.whl.

File metadata

File hashes

Hashes for stack_graphs_python_bindings-0.0.14-cp313-cp313-win32.whl
Algorithm Hash digest
SHA256 ab9cb4d175836a4ec2e4519ba7afc70177c8cfbc7c5d213370a65c188bf60eda
MD5 7c61c3b5f969393044bc60afc43e52c6
BLAKE2b-256 ee1002ddbdf50b6b85ddc03991584e608a95f5ad7ce8b193aa07e7d82728cb4e

See more details on using hashes here.

File details

Details for the file stack_graphs_python_bindings-0.0.14-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for stack_graphs_python_bindings-0.0.14-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8fcc6a4a2bed8944fb2f31d889d62e5bae7ba696909aeefb8348cfd4ee2f673a
MD5 536743c46f3022e8f6c676de87294ed4
BLAKE2b-256 d181b4d532f061785e60d4acf97dc03159abe42485481aa662634f9ebd32fc40

See more details on using hashes here.

File details

Details for the file stack_graphs_python_bindings-0.0.14-cp313-cp313-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for stack_graphs_python_bindings-0.0.14-cp313-cp313-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 8b435bda8ff6cd6eba14c563cc0e045a20393415d4468fa8870f372de2c034d2
MD5 8df5b93a2c6291c1b9d7a41a9c3f3591
BLAKE2b-256 f7f2e063f21525c85de401f11ccb02158d6197aa8670298a3de26c9a3743fc08

See more details on using hashes here.

File details

Details for the file stack_graphs_python_bindings-0.0.14-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for stack_graphs_python_bindings-0.0.14-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 c60d921549609a2e2bbb80bbadae432552502af1c7e720790182d2b945901573
MD5 e0028c5471fc426dcdc3420423e7ad2a
BLAKE2b-256 f6d20eef216ff3c237d258e393a2e2e375a986be5dd364be5b8eead0437cab4b

See more details on using hashes here.

File details

Details for the file stack_graphs_python_bindings-0.0.14-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for stack_graphs_python_bindings-0.0.14-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9a33fc075b234a7c4475724f8826098c1355502a5c2ebe28709b68d5c93153ca
MD5 a7c3c6ed2761ff58e0d73f5d188b5f74
BLAKE2b-256 4bec45a1036164a2fc689cae8f6bf08ee76b466fd333bcba983a71d118dc6e4d

See more details on using hashes here.

File details

Details for the file stack_graphs_python_bindings-0.0.14-cp313-cp313-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for stack_graphs_python_bindings-0.0.14-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 760e9351d5c46d1da94c4d989ade571a279a03a4972477d00768893346265ec4
MD5 c5796b181826fd95b179df07e1fa5f43
BLAKE2b-256 a3fc94027b1f28fd49e39a00ed3b9310c768aa026d4e9c906e48a540ad1a8016

See more details on using hashes here.

File details

Details for the file stack_graphs_python_bindings-0.0.14-cp312-cp312-win32.whl.

File metadata

File hashes

Hashes for stack_graphs_python_bindings-0.0.14-cp312-cp312-win32.whl
Algorithm Hash digest
SHA256 de8ec4ed5c4611cc43489b4b3c9f4b70e1381dad93d50416a434ac7ea691849f
MD5 7092d93163d7d533ed3ed8839bb799ef
BLAKE2b-256 c0914f1013dc7f714ff5a46c61907053f624200fdc501144c1c8b69c8adb3dd4

See more details on using hashes here.

File details

Details for the file stack_graphs_python_bindings-0.0.14-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for stack_graphs_python_bindings-0.0.14-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1572d954b670fb3668f0eb6e2284d830ec97fca69a54feb45832152dcf9f5562
MD5 9761f288a879861aa52c07aeb3eb5aab
BLAKE2b-256 23be62e706ea3ef83b3b01beb05e314a19e20bc882a599468d5f8b3374033625

See more details on using hashes here.

File details

Details for the file stack_graphs_python_bindings-0.0.14-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for stack_graphs_python_bindings-0.0.14-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 c0397a24771a5dd8cd9440db9a81a20349295edebadb7563801a3c4170e20e9a
MD5 3f8fe1a8f75b3e82c7113ed6a4ca27e2
BLAKE2b-256 9b1f7f69bca5488656900feb442f2cd78f425c774a90d4bff378e3d4341942e2

See more details on using hashes here.

File details

Details for the file stack_graphs_python_bindings-0.0.14-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for stack_graphs_python_bindings-0.0.14-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 da9b0c760a63066b18b9bf4cb0582ecf1310aa5ec537c5dbb3875048ad18fe87
MD5 d4f2b09c32fef5a5367e656dab82c630
BLAKE2b-256 aa6790def0e77cbd62daa4d75ef52c96d3776c7494a151983e6e2d094d7eedcc

See more details on using hashes here.

File details

Details for the file stack_graphs_python_bindings-0.0.14-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for stack_graphs_python_bindings-0.0.14-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 63ae76e66ad64e7d28c54c2fa9db9c48cf19393d7122cb9eeadbfa646ff984b3
MD5 d9fffa90ba0dd5596b67a0592cff2f83
BLAKE2b-256 b957f4edabcdb7f8c55506561ff188cad5d89a3cfa4680531b19c09eb49a3fa6

See more details on using hashes here.

File details

Details for the file stack_graphs_python_bindings-0.0.14-cp312-cp312-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for stack_graphs_python_bindings-0.0.14-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 46d7675560b731155e86b6ca9b87ac257d8852ef62ab949f73f790a6c7585b5b
MD5 f10d23097acda79fd582a3fbf25b0354
BLAKE2b-256 6d1547a8d7304038e9add45e72a6c6dec09ced6eff505880d1ce12656f65f3d2

See more details on using hashes here.

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