Skip to main content

Xylem

pypi license

Convert Python Abstract Syntax Trees (ASTs) to readable source code.

Xylem is useful for when you want to make dynamic changes to Python code/ASTs, but also need to write those changes back as source code.

It’s also very small (<500 lines), pure-Python, and produces (mostly) readable source code.

In writing this, I made heavy use of the unofficial AST documentation at Green Tree Snakes.

Installation

Xylem will work on Python 3.4 or later. I’ll eventually get around to testing it on Python 2.7-3.3.

From PyPI

Install Xylem by running pip3 install xylem from the command line.

From GitHub

Clone or download the git repo, navigate to the directory, and run:

python3 setup.py sdist
cd dist
pip3 install xylem-<version>.tar.gz

Usage

to_source is likely the only method you’ll need to use:

>>> from xylem import to_source
>>> import ast
>>> tree = ast.parse("print('hello world')")
>>> ast.dump(tree)
"Module(body=[Expr(value=Call(func=Name(id='print', ctx=Load()), args=[Str(s='Hello world')], keywords=[]))])"
>>> to_source(tree)
"print('hello world')"

compare_ast may also be useful for determining if two ASTs are functionally equivalent.

Development

Xylem versioning functions on a MAJOR.MINOR.PATCH.[DEVELOP] model. Only stable, non development releases will be published to PyPI. Because Xylem is still a beta project, the MAJOR increment will be 0. Minor increments represent new features. Patch increments represent problems fixed with existing features.

Metadata

Release files for xylem 0.10.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 xylem 0.10.0
File Size Uploaded Provenance
xylem-0.10.0.tar.gz 7.2 kB Without provenance Details

Release files / xylem-0.10.0.tar.gz

Download URL xylem-0.10.0.tar.gz
Size 7.2 kB
Tags Source
SHA-256 checksum
How to use checksums
3bfd065b785c10704e9f2a07d168e66fe381b1cdc245fc5a067967b02565efce
BLAKE2b-256 checksum
How to use checksums
ed5c4997d1c599a235b75cb0d60a487a0097b1a8dcd9f5878906c2be2fd87fc9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Python-urllib/3.6

Security for xylem 0.10.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