Skip to main content

Query AST elements by using CSS Selector-like syntax

Project description

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.

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

ast_selector-0.1.4.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

ast_selector-0.1.4-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file ast_selector-0.1.4.tar.gz.

File metadata

  • Download URL: ast_selector-0.1.4.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.10.4 Linux/5.15.0-35-generic

File hashes

Hashes for ast_selector-0.1.4.tar.gz
Algorithm Hash digest
SHA256 f9301f0de2a12a78aab4dd0991f127b875e88d236afb5cd713d8d3f235f0ce5f
MD5 fc2c3ce4a7efbe4d4b030da7aab3eb30
BLAKE2b-256 380d97222d500fcc7ed226c14b833fccc02713398607f731bf0aebcf37bb3fd9

See more details on using hashes here.

File details

Details for the file ast_selector-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: ast_selector-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.10.4 Linux/5.15.0-35-generic

File hashes

Hashes for ast_selector-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 b830c9b1d9a170b8266cdcd35f85b1e0d21d6e5646c830c5385a8a3643254eaa
MD5 cdfb24b0c868273a56206b26535d922e
BLAKE2b-256 2efc82ca5c9694ac7807c61270ae124e12f6defc1db49ba3d7fa0f8a1cbfe4c8

See more details on using hashes here.

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