Name | astlab JSON |
Version |
0.1.0
JSON |
| download |
home_page | None |
Summary | provides an intuitive API for building and manipulating Abstract Syntax Trees (ASTs) to generate Python code. |
upload_time | 2025-01-23 22:52:29 |
maintainer | None |
docs_url | None |
author | zerlok |
requires_python | <4.0,>=3.9 |
license | MIT |
keywords |
python
codegen
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# astlab
[![Latest Version](https://img.shields.io/pypi/v/astlab.svg)](https://pypi.python.org/pypi/astlab)
[![Python Supported Versions](https://img.shields.io/pypi/pyversions/astlab.svg)](https://pypi.python.org/pypi/astlab)
[![MyPy Strict](https://img.shields.io/badge/mypy-strict-blue)](https://mypy.readthedocs.io/en/stable/getting_started.html#strict-mode-and-configuration)
[![Test Coverage](https://codecov.io/gh/zerlok/astlab/branch/main/graph/badge.svg)](https://codecov.io/gh/zerlok/astlab)
[![Downloads](https://img.shields.io/pypi/dm/astlab.svg)](https://pypistats.org/packages/astlab)
[![GitHub stars](https://img.shields.io/github/stars/zerlok/astlab)](https://github.com/zerlok/astlab/stargazers)
**astlab** is a Python library that provides an intuitive API for building and manipulating Abstract Syntax Trees (ASTs) to generate Python code. With **astlab**, you can easily create Python modules, classes, fields, and more using a simple and readable syntax, and convert the AST back into executable Python code.
## Features
- **Easy AST construction**: Build Python code using a fluent and intuitive API.
- **Code generation**: Convert your AST into valid Python code, forget about jinja templates.
- **Supports nested scopes & auto imports**: Create nested classes, methods, and fields effortlessly. Reference types from other modules easily.
- **Highly customizable**: Extend and modify the API to suit your needs.
## Installation
You can install **astlab** from PyPI using `pip`:
```bash
pip install astlab
```
## Usage
### Simple example
Here's a basic example of how to use **astlab** to create a Python module with a dataclass.
```python
import astlab
# Create a new Python module
with astlab.module("foo") as foo:
# Build a "Bar" dataclass
with foo.class_def("Bar").dataclass() as bar:
# Define a field "spam" of type int
bar.field_def("spam", int)
# Generate and print the Python code from the AST
print(foo.render())
```
### Output:
```python
import builtins
import dataclasses
@dataclasses.dataclass()
class Bar:
spam: builtins.int
```
Raw data
{
"_id": null,
"home_page": null,
"name": "astlab",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.9",
"maintainer_email": null,
"keywords": "python, codegen",
"author": "zerlok",
"author_email": "danil.troshnev@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/6c/25/81725cfb619fb930d05d544cf246ca37de7dba4e710fdab6f8b98b138764/astlab-0.1.0.tar.gz",
"platform": null,
"description": "# astlab\n\n[![Latest Version](https://img.shields.io/pypi/v/astlab.svg)](https://pypi.python.org/pypi/astlab)\n[![Python Supported Versions](https://img.shields.io/pypi/pyversions/astlab.svg)](https://pypi.python.org/pypi/astlab)\n[![MyPy Strict](https://img.shields.io/badge/mypy-strict-blue)](https://mypy.readthedocs.io/en/stable/getting_started.html#strict-mode-and-configuration)\n[![Test Coverage](https://codecov.io/gh/zerlok/astlab/branch/main/graph/badge.svg)](https://codecov.io/gh/zerlok/astlab)\n[![Downloads](https://img.shields.io/pypi/dm/astlab.svg)](https://pypistats.org/packages/astlab)\n[![GitHub stars](https://img.shields.io/github/stars/zerlok/astlab)](https://github.com/zerlok/astlab/stargazers)\n\n**astlab** is a Python library that provides an intuitive API for building and manipulating Abstract Syntax Trees (ASTs) to generate Python code. With **astlab**, you can easily create Python modules, classes, fields, and more using a simple and readable syntax, and convert the AST back into executable Python code.\n\n## Features\n\n- **Easy AST construction**: Build Python code using a fluent and intuitive API.\n- **Code generation**: Convert your AST into valid Python code, forget about jinja templates.\n- **Supports nested scopes & auto imports**: Create nested classes, methods, and fields effortlessly. Reference types from other modules easily.\n- **Highly customizable**: Extend and modify the API to suit your needs.\n\n## Installation\n\nYou can install **astlab** from PyPI using `pip`:\n\n```bash\npip install astlab\n```\n\n## Usage\n\n### Simple example\n\nHere's a basic example of how to use **astlab** to create a Python module with a dataclass.\n\n```python\nimport astlab\n\n# Create a new Python module\nwith astlab.module(\"foo\") as foo:\n # Build a \"Bar\" dataclass\n with foo.class_def(\"Bar\").dataclass() as bar:\n # Define a field \"spam\" of type int\n bar.field_def(\"spam\", int)\n\n# Generate and print the Python code from the AST\nprint(foo.render())\n```\n\n### Output:\n\n```python\nimport builtins\nimport dataclasses\n\n@dataclasses.dataclass()\nclass Bar:\n spam: builtins.int\n```\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "provides an intuitive API for building and manipulating Abstract Syntax Trees (ASTs) to generate Python code.",
"version": "0.1.0",
"project_urls": {
"Homepage": "https://github.com/zerlok/astlab",
"Issues": "https://github.com/zerlok/astlab/issues"
},
"split_keywords": [
"python",
" codegen"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f41faeeb37f177a0aec44b20079b28c5664b5ac0701d61a5de14c1645d1d9dff",
"md5": "cb9a0496c4eaf8fe28aee54db9206e15",
"sha256": "2ccf691cdb4004419ab7e6270821e1b786b0c322f0c90afb74c7e6bb018cbfc4"
},
"downloads": -1,
"filename": "astlab-0.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "cb9a0496c4eaf8fe28aee54db9206e15",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.9",
"size": 15841,
"upload_time": "2025-01-23T22:52:27",
"upload_time_iso_8601": "2025-01-23T22:52:27.317895Z",
"url": "https://files.pythonhosted.org/packages/f4/1f/aeeb37f177a0aec44b20079b28c5664b5ac0701d61a5de14c1645d1d9dff/astlab-0.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "6c2581725cfb619fb930d05d544cf246ca37de7dba4e710fdab6f8b98b138764",
"md5": "be205d6151337ef7d34b0e1eacb6e336",
"sha256": "7212e6db1b54eeeeafec2cbc635abdcba53b1d7c4c735e2b8459294076924556"
},
"downloads": -1,
"filename": "astlab-0.1.0.tar.gz",
"has_sig": false,
"md5_digest": "be205d6151337ef7d34b0e1eacb6e336",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.9",
"size": 14586,
"upload_time": "2025-01-23T22:52:29",
"upload_time_iso_8601": "2025-01-23T22:52:29.305170Z",
"url": "https://files.pythonhosted.org/packages/6c/25/81725cfb619fb930d05d544cf246ca37de7dba4e710fdab6f8b98b138764/astlab-0.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-01-23 22:52:29",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "zerlok",
"github_project": "astlab",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "astlab"
}