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.1.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.1-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyastgen-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 89cfe047b8a650cb303a7cfaf3e80435152a61036eeddc90f68ded898ebf28d1
MD5 1ce52ee4b04b34cf398856bb4f3974a2
BLAKE2b-256 f5c16f0b0e7e90988dee6896292f34320a116e62ac49c3f465f43337fee582d1

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyastgen-0.1.1.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.1-py3-none-any.whl.

File metadata

  • Download URL: pyastgen-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8e4dfd2ce80e903f9ddac4c4544480789e4106eb2fb280af49661bef22bbd884
MD5 04776f92acff6495e81ea3061c54fb3a
BLAKE2b-256 56739205e75efbf0c42df930fe51aae765fd885e1d02919b34f58e4204172a14

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyastgen-0.1.1-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