Skip to main content

AST Selector

Query AST elements by using CSS Selector-like syntax

Actions Status PyPI Semantic Release GitHub Downloads Code style: black try/except style: tryceratops Follow guilatrova

"Query AST elements 🌲 by using CSS Selector-like 💅 syntax."

Installation and usage

Installation

pip install ast-selector

Usage

from ast_selector import AstSelector

tree = load_python_code_as_ast_tree()
query = "FunctionDef Raise $FunctionDef"
# Query all functions that raises at least an exception

functions_raising_exceptions = AstSelector(query, tree).all()

Use Cases

Functions that return int

from ast_selector import AstSelector

tree = load_python_code_as_ast_tree()
query = "FunctionDef.returns[id=int] $FunctionDef"
# Query all functions that return ints e.g. def sum() -> int

function_element = AstSelector(query, tree).first()

License

MIT

Credits

It's extremely hard to keep hacking on open source like that while keeping a full-time job. I thank God from the bottom of my heart for both the inspiration and the energy.

Release files for ast-selector 0.2.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 ast-selector 0.2.0
File Size Uploaded
ast_selector-0.2.0.tar.gz 6.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ast-selector 0.2.0
File Interpreter ABI Platform
ast_selector-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 13.4 kB

Release files / ast_selector-0.2.0.tar.gz

Download URL ast_selector-0.2.0.tar.gz
Size 6.2 kB
Tags Source
SHA-256 checksum
How to use checksums
6991884efd4248060ecf3da169e8ade4d48d2ab64fdb99046afbcb98aa5a27a1
BLAKE2b-256 checksum
How to use checksums
6fd7efea6d20f174e549766e09f46e6f3ed646c32d16e1b5ec44af892c533cc6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.3 readme-renderer/35.0 requests/2.28.0 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.64.0 importlib-metadata/4.2.0 keyring/23.6.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.10

Release files / ast_selector-0.2.0-py3-none-any.whl

Download URL ast_selector-0.2.0-py3-none-any.whl
Size 7.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dfcc130fdf9bdc7cd105f5d53fc5acd575a4067c6710b1d909fe1e68bf411388
BLAKE2b-256 checksum
How to use checksums
9d50f81b5caed1b90a32ca494b3f4a66c50897f36960adb4789a17efae80549c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.3 readme-renderer/35.0 requests/2.28.0 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.64.0 importlib-metadata/4.2.0 keyring/23.6.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.10

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 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