Skip to main content

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:

Metadata

Release files for astars 0.1.0

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

Source distribution (sdist)

Source distribution for astars 0.1.0
File Size Uploaded Provenance Actions
astars-0.1.0.tar.gz 65.5 kB Without provenance Details for astars-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for astars 0.1.0
File Interpreter ABI Platform Actions
astars-0.1.0-py3-none-any.whl Python 3 none any Details for astars-0.1.0-py3-none-any.whl

Total release size: 97.0 kB

Release files / astars-0.1.0.tar.gz

Download URL astars-0.1.0.tar.gz
Size 65.5 kB
Tags Source
SHA-256 checksum
How to use checksums
acd4124ff4978ce7f4e45e4bf9a50f6e601c0e61f730af52da864499c0597d65
BLAKE2b-256 checksum
How to use checksums
82a0afb0dc1d88b559b0b5864e67194480740d41d06d631511b9c5122e93a167
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release files / astars-0.1.0-py3-none-any.whl

Download URL astars-0.1.0-py3-none-any.whl
Size 31.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dd2c57e6d2370ade88b98a00609414f94e8771a097c4c8869f81b976479b5d5a
BLAKE2b-256 checksum
How to use checksums
315c2788986dfcefb33e2f98e1b2974283e7d800221f332881f30d6a232a7305
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Security for astars 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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