Skip to main content

A lightweight program-structure engine.

Project description

Astars logo

Astars

A lightweight program-structure engine.

Astars parses source code into an AST-like structure, lets users inspect and query that structure, and maps nodes back to their original source spans and source text. Astars is intended to be a small engine that downstream packages can build on, rather than a full analysis product by itself.

Project Status

Astars 0.1.0 provides the first v0 public API.

The current v0 scope is intentionally small:

  • parse Python source code
  • inspect AST-like nodes without touching parser-specific objects
  • find nodes by kind
  • map nodes to byte spans and source text
  • provide a stable entry point for downstream astars-* packages

The following are outside the v0 scope:

  • source editing primitives
  • semantic analysis
  • multi-language support
  • metrics, code review, pruning, or LLM-specific policies
  • stable compatibility for legacy AParser, APruner, or ATraverser APIs

Installation

Astars currently requires Python 3.10 or newer.

For the released package:

pip install astars

To try the development version from this repository:

git clone https://github.com/xwasoux/astars.git
cd astars
pip install -e .

Quick Start

import astars

source = "def hello(name):\n    return name\n"

unit = astars.parse_str(source, lang="python")

print(unit.lang)
print(unit.root.kind)

function = unit.find(kind="FunctionDef")[0]

print(unit.span_of(function))
print(unit.source_of(function))
print(unit.node_at(4).kind)

Expected output:

python
Module
SourceSpan(start_byte=0, end_byte=32, start_point=(0, 0), end_point=(1, 15))
def hello(name):
    return name
Identifier

Public API

Astars exposes the v0 API from the top-level astars package:

import astars

unit = astars.parse_file("example.py", lang="python")
unit = astars.parse_str("x = 1\n", lang="python")
unit = astars.parse_bytes(b"x = 1\n", lang="python")

Each parse function returns a SourceUnit.

root = unit.root
diagnostics = unit.diagnostics

for node in unit.walk():
    print(node.kind)

functions = unit.find(kind="FunctionDef")
node = unit.node_at(byte_offset=4)

span = unit.span_of(functions[0])
source_text = unit.source_of(functions[0])

Important public objects:

  • astars.SourceUnit
  • astars.SourceSpan
  • astars.Diagnostic
  • astars.AstarsError
  • astars.UnsupportedLanguageError
  • astars.ParserUnavailableError

Design Boundary

Astars is an engine layer. It should answer questions such as:

  • What is the program structure of this source file?
  • Which nodes match this structural query?
  • Where did this node come from in the original source?
  • What source text corresponds to this node?

Astars should not decide what a metric means, whether a code review finding is important, or which LLM evaluation policy should be applied. Those decisions belong in downstream packages such as astars-metrics, astars-code-review, or astars-llm-eval.

Development

Run the test suite with:

python -m pytest

The v0 public API is covered by tests/test_public_api.py.

Design Documents

The current strategy and architecture notes are maintained in Japanese:

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

astars-0.1.0.tar.gz (65.5 kB view details)

Uploaded Source

Built Distribution

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

astars-0.1.0-py3-none-any.whl (31.5 kB view details)

Uploaded Python 3

File details

Details for the file astars-0.1.0.tar.gz.

File metadata

  • Download URL: astars-0.1.0.tar.gz
  • Upload date:
  • Size: 65.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for astars-0.1.0.tar.gz
Algorithm Hash digest
SHA256 acd4124ff4978ce7f4e45e4bf9a50f6e601c0e61f730af52da864499c0597d65
MD5 8bf961ebd85fdcf9f7a82d397c45a5ca
BLAKE2b-256 82a0afb0dc1d88b559b0b5864e67194480740d41d06d631511b9c5122e93a167

See more details on using hashes here.

File details

Details for the file astars-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: astars-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 31.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for astars-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dd2c57e6d2370ade88b98a00609414f94e8771a097c4c8869f81b976479b5d5a
MD5 8bbfe06e9965cb3f020d737516df1f41
BLAKE2b-256 315c2788986dfcefb33e2f98e1b2974283e7d800221f332881f30d6a232a7305

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