Skip to main content

Synt

Write Python with Python. Inspired by jennifer.

Python-3.12 GitHub top language GitHub Actions Workflow Status Codecov PyPI - Downloads PyPI - License PyPI - Version

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

Documentation


Installation

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

pip install synt

Then, import Synt:

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:

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:

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 page.

Metadata

Release files for synt 0.4.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 synt 0.4.0
File Size Uploaded Provenance Actions
synt-0.4.0.tar.gz 38.4 kB Without provenance Details for synt-0.4.0.tar.gz

Built distribution (wheel)

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

Total release size: 98.5 kB

Release files / synt-0.4.0.tar.gz

Download URL synt-0.4.0.tar.gz
Size 38.4 kB
Tags Source
SHA-256 checksum
How to use checksums
cd7729e8ffddea1bf231864c8b4f4ad4963519dcadc200023c0549872761632b
BLAKE2b-256 checksum
How to use checksums
b2f2e018910b260a2d72cf3807093ec70314153dde48c6950a594a4872ab0383
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.12.4 Linux/6.5.0-1023-azure

Release files / synt-0.4.0-py3-none-any.whl

Download URL synt-0.4.0-py3-none-any.whl
Size 60.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8cdeab25f5de40e8906b94a85ce14a275ebb95b0e52971d04d1fcf7e44b98d78
BLAKE2b-256 checksum
How to use checksums
c351a652e3d8e242361227f8e89b95bd9ebf1826203fc07cc995fd3b61bebaa0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.12.4 Linux/6.5.0-1023-azure

Security for synt 0.4.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.

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