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 very few, easy to use functions to index files and query references.

This is a proof of concept draft, to test scripting utilities using stack-graphs easily.

It uses pyo3 and maturin to generate the bindings.

Installation & Usage

pip install stack-graphs-python-bindings # or poetry, ...
import os
from stack_graphs_python import index, Querier, Position, Language

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

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

# 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(f"{r.path}, l:{r.line}, c: {r.column}")

Will result in:

[...]/stack-graphs-python-bindings/tests/js_sample/index.js, l:0, c: 9
[...]/stack-graphs-python-bindings/tests/js_sample/module.js, l:0, c: 13

That translates to:

// index.js
import { foo } from "./module"

// module.js
export const foo = "bar"

Development

Ressources

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

Requirements

  • Rust
  • Python 3.11+

Setup

# Setup venv and install maturin through pip
make setup

Testing

make test

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.9.tar.gz (24.3 kB view hashes)

Uploaded Source

Built Distributions

stack_graphs_python_bindings-0.0.9-cp312-none-win32.whl (2.8 MB view hashes)

Uploaded CPython 3.12 Windows x86

stack_graphs_python_bindings-0.0.9-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.4 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

stack_graphs_python_bindings-0.0.9-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl (4.6 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ i686

stack_graphs_python_bindings-0.0.9-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (6.6 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ARM64

stack_graphs_python_bindings-0.0.9-cp312-cp312-macosx_11_0_arm64.whl (3.2 MB view hashes)

Uploaded CPython 3.12 macOS 11.0+ ARM64

stack_graphs_python_bindings-0.0.9-cp312-cp312-macosx_10_12_x86_64.whl (3.4 MB view hashes)

Uploaded CPython 3.12 macOS 10.12+ x86-64

stack_graphs_python_bindings-0.0.9-cp311-none-win32.whl (2.8 MB view hashes)

Uploaded CPython 3.11 Windows x86

stack_graphs_python_bindings-0.0.9-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.4 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

stack_graphs_python_bindings-0.0.9-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl (4.6 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ i686

stack_graphs_python_bindings-0.0.9-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (6.6 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

stack_graphs_python_bindings-0.0.9-cp311-cp311-macosx_11_0_arm64.whl (3.2 MB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

stack_graphs_python_bindings-0.0.9-cp311-cp311-macosx_10_12_x86_64.whl (3.4 MB view hashes)

Uploaded CPython 3.11 macOS 10.12+ x86-64

Supported by

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