synt


Namesynt JSON
Version 0.4.0 PyPI version JSON
download
home_pagehttps://github.com/Embers-of-the-Fire/synt/
SummaryWrite python with python.
upload_time2024-07-22 02:02:23
maintainerNone
docs_urlNone
authorEmbers-of-the-Fire
requires_python<4.0,>=3.12
licenseMIT OR Apache-2.0
keywords syntax code generator template
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Synt

<i>Write Python with Python.&emsp;<small>Inspired by [jennifer](https://github.com/dave/jennifer).</small></i>

![Python-3.12](https://img.shields.io/badge/Python-3.12-blue?style=for-the-badge)
![GitHub top language](https://img.shields.io/github/languages/top/Embers-of-the-Fire/synt?style=for-the-badge&color=yellow)
![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/Embers-of-the-Fire/synt/CI.yaml?style=for-the-badge)
![Codecov](https://img.shields.io/codecov/c/github/Embers-of-the-Fire/synt?style=for-the-badge)
![PyPI - Downloads](https://img.shields.io/pypi/dm/synt?style=for-the-badge)
![PyPI - License](https://img.shields.io/pypi/l/synt?style=for-the-badge)
![PyPI - Version](https://img.shields.io/pypi/v/synt?style=for-the-badge)

Synt is a library for developers to write elegant machine-generated Python code.

[Documentation][github-page-doc]

---

## Installation

To install Synt, use your preferred package manager and add `synt` to your dependencies, e.g. by pip:

```bash
pip install synt
```

Then, import Synt:

```python
import synt                    # directly import Synt, or
from synt.prelude import *     # import pre-organized utilities from `prelude`.
```

## Overview

Synt creates a Python-based DSL for writing actual Python code.

Different from text-based template systems like Jinja,
Synt allows you to construct Python code generator as-is:

```python
from synt.prelude import *

expression = id_("foo") \
    .expr() \
    .attr("bar") \
    .call(buzz=id_("buzz"))

assert expression.into_code() == "foo.bar(buzz=buzz)"
```

## Usage

Synt keeps most of Python's standard operations as-is.
Currently, Synt only supports generating expressions,
and statement generating is on the to-do list.

Typically, special syntax in Python can be used with alias methods with the same name.
For example, the following example shows how to create a generator comprehension:

```python
from synt.prelude import *

comp = fstring("Item: ", fnode(id_("x"))) \
    .for_(id_("x")) \
    .in_(id_("it"))

# note: Comprehension expressions are a bit different
#       because it accepts any amount of `for`s and `if`s.
#       Thus we must add a `.expr()` to force it to be an expression.
assert comp.expr().into_code() == r'(f"Item: {x}" for x in it)'
```

For full api documentation, see the [Documentation][github-page-doc] page.

[github-page-doc]: https://embers-of-the-fire.github.io/synt/

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Embers-of-the-Fire/synt/",
    "name": "synt",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.12",
    "maintainer_email": null,
    "keywords": "syntax, code, generator, template",
    "author": "Embers-of-the-Fire",
    "author_email": "stellarishs@163.com",
    "download_url": "https://files.pythonhosted.org/packages/b2/f2/e018910b260a2d72cf3807093ec70314153dde48c6950a594a4872ab0383/synt-0.4.0.tar.gz",
    "platform": null,
    "description": "# Synt\n\n<i>Write Python with Python.&emsp;<small>Inspired by [jennifer](https://github.com/dave/jennifer).</small></i>\n\n![Python-3.12](https://img.shields.io/badge/Python-3.12-blue?style=for-the-badge)\n![GitHub top language](https://img.shields.io/github/languages/top/Embers-of-the-Fire/synt?style=for-the-badge&color=yellow)\n![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/Embers-of-the-Fire/synt/CI.yaml?style=for-the-badge)\n![Codecov](https://img.shields.io/codecov/c/github/Embers-of-the-Fire/synt?style=for-the-badge)\n![PyPI - Downloads](https://img.shields.io/pypi/dm/synt?style=for-the-badge)\n![PyPI - License](https://img.shields.io/pypi/l/synt?style=for-the-badge)\n![PyPI - Version](https://img.shields.io/pypi/v/synt?style=for-the-badge)\n\nSynt is a library for developers to write elegant machine-generated Python code.\n\n[Documentation][github-page-doc]\n\n---\n\n## Installation\n\nTo install Synt, use your preferred package manager and add `synt` to your dependencies, e.g. by pip:\n\n```bash\npip install synt\n```\n\nThen, import Synt:\n\n```python\nimport synt                    # directly import Synt, or\nfrom synt.prelude import *     # import pre-organized utilities from `prelude`.\n```\n\n## Overview\n\nSynt creates a Python-based DSL for writing actual Python code.\n\nDifferent from text-based template systems like Jinja,\nSynt allows you to construct Python code generator as-is:\n\n```python\nfrom synt.prelude import *\n\nexpression = id_(\"foo\") \\\n    .expr() \\\n    .attr(\"bar\") \\\n    .call(buzz=id_(\"buzz\"))\n\nassert expression.into_code() == \"foo.bar(buzz=buzz)\"\n```\n\n## Usage\n\nSynt keeps most of Python's standard operations as-is.\nCurrently, Synt only supports generating expressions,\nand statement generating is on the to-do list.\n\nTypically, special syntax in Python can be used with alias methods with the same name.\nFor example, the following example shows how to create a generator comprehension:\n\n```python\nfrom synt.prelude import *\n\ncomp = fstring(\"Item: \", fnode(id_(\"x\"))) \\\n    .for_(id_(\"x\")) \\\n    .in_(id_(\"it\"))\n\n# note: Comprehension expressions are a bit different\n#       because it accepts any amount of `for`s and `if`s.\n#       Thus we must add a `.expr()` to force it to be an expression.\nassert comp.expr().into_code() == r'(f\"Item: {x}\" for x in it)'\n```\n\nFor full api documentation, see the [Documentation][github-page-doc] page.\n\n[github-page-doc]: https://embers-of-the-fire.github.io/synt/\n",
    "bugtrack_url": null,
    "license": "MIT OR Apache-2.0",
    "summary": "Write python with python.",
    "version": "0.4.0",
    "project_urls": {
        "Documentation": "https://embers-of-the-fire.github.io/synt/",
        "Homepage": "https://github.com/Embers-of-the-Fire/synt/",
        "Repository": "https://github.com/Embers-of-the-Fire/synt.git"
    },
    "split_keywords": [
        "syntax",
        " code",
        " generator",
        " template"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c351a652e3d8e242361227f8e89b95bd9ebf1826203fc07cc995fd3b61bebaa0",
                "md5": "54e3a166d1afcc7971e1934193428314",
                "sha256": "8cdeab25f5de40e8906b94a85ce14a275ebb95b0e52971d04d1fcf7e44b98d78"
            },
            "downloads": -1,
            "filename": "synt-0.4.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "54e3a166d1afcc7971e1934193428314",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.12",
            "size": 60115,
            "upload_time": "2024-07-22T02:02:22",
            "upload_time_iso_8601": "2024-07-22T02:02:22.284322Z",
            "url": "https://files.pythonhosted.org/packages/c3/51/a652e3d8e242361227f8e89b95bd9ebf1826203fc07cc995fd3b61bebaa0/synt-0.4.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b2f2e018910b260a2d72cf3807093ec70314153dde48c6950a594a4872ab0383",
                "md5": "2702cc3351cc3a6d7ec1fd525802ceeb",
                "sha256": "cd7729e8ffddea1bf231864c8b4f4ad4963519dcadc200023c0549872761632b"
            },
            "downloads": -1,
            "filename": "synt-0.4.0.tar.gz",
            "has_sig": false,
            "md5_digest": "2702cc3351cc3a6d7ec1fd525802ceeb",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.12",
            "size": 38434,
            "upload_time": "2024-07-22T02:02:23",
            "upload_time_iso_8601": "2024-07-22T02:02:23.676934Z",
            "url": "https://files.pythonhosted.org/packages/b2/f2/e018910b260a2d72cf3807093ec70314153dde48c6950a594a4872ab0383/synt-0.4.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-22 02:02:23",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Embers-of-the-Fire",
    "github_project": "synt",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "synt"
}
        
Elapsed time: 2.21778s