Skip to main content

Python library for generating Python

Project description

pyastgen

Builder for generating Python source, inspired by llvmlite.

For example, the following code generates a fibonacci function:

import pyastgen

module, builder = pyastgen.new_module()

fib = builder.declare("fib")
(n,), fib_builder = builder.new_function(fib, pyastgen.Parameters("n"))
then, _else = fib_builder.if_(n.lt(pyastgen.constant(2)))
then.return_(n)
fib_builder.return_(
    fib.call(n.sub(pyastgen.constant(1))).add(
        fib.call(n.sub(pyastgen.constant(2)))
    )
)

print(pyastgen.unparse(module))

Output:

def fib(n, /):
    if n < 2:
        return n
    return fib(n - 1) + fib(n - 2)

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

pyastgen-0.1.0.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyastgen-0.1.0-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file pyastgen-0.1.0.tar.gz.

File metadata

  • Download URL: pyastgen-0.1.0.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pyastgen-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3d00591e996d13c24b25ec050918f782eca132c321ddaa2d6a00dd59e6996743
MD5 741c10ac13dbdaffaec2bc1928df4b09
BLAKE2b-256 2215014a50bfd36873a4d5d867c1ba5ba202daac7840655e91293fa4878ca98b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyastgen-0.1.0.tar.gz:

Publisher: python-publish.yml on p7g/pyastgen

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyastgen-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pyastgen-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pyastgen-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3348f7699c15e2c293e621ba4be5a7a9ea43c6184abddaba68057af694f3bf95
MD5 59bb7cc399a16114d3cedd978fdd1d62
BLAKE2b-256 18fbdf7b29efc169d1157f99c39c3201a98eb9c0a90f35d3fb179f9596dfcbf1

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyastgen-0.1.0-py3-none-any.whl:

Publisher: python-publish.yml on p7g/pyastgen

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page