Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

wesley-python

A Wesley target that emits stdlib-only Python: TypedDict models embeddable in a single-file module.

Wesley compiles GraphQL SDL into an intermediate representation (IR), and does nothing else: it attaches no meaning to any directive and runs no targets. Every output language is its own repository, a standalone program and library that reads the IR (wesley schema lower --json). This one is a generic target: it understands no directives and emits Python from plain GraphQL, and it is the language tooling other targets (such as wesley-parley) render through. The decisions are recorded in flyingrobots/parley#116 and flyingrobots/wesley#882.

Status

The first release is 0.1.0a1, a pre-release: the package wesley_python, with a syntax API for building Python modules of TypedDict classes and type aliases, and a plain-GraphQL emitter on the command line. It reads IR version 1.0.0 as Wesley prints it today; the versioned IR contract is still flyingrobots/wesley#881. There is no --fragment mode, no marker-wrapped output and no generated header naming the schema hash yet (#1).

The package runs on Python 3.9 or later and imports nothing outside the standard library. Its generated modules do the same.

Install

pip install wesley-python==0.1.0a1

The package is wesley-python on PyPI and wesley_python to import. While every release is a pre-release, pip install wesley-python needs --pre or an exact version.

Usage

The command line

wesley schema lower --schema schema.graphql --json | python -m wesley_python emit > models.py
python -m wesley_python emit --ir ir.json --out models.py

emit reads Wesley IR JSON from --ir (standard input by default) and writes a module to --out (standard output by default). An IR whose version is not 1.0.0, malformed IR or invalid JSON is an error: a message on standard error and exit status 1. Installing the package also installs the same command as wesley-python.

The emitter is generic: it ignores every directive. It maps GraphQL as follows.

GraphQL Python
type, input, interface a TypedDict; every field is a required key
nullable field T Union[T, None]: GraphQL null is a value, not an absent key
[T!], [T] List[T], List[Union[T, None]]
enum an alias of Literal['A', 'B', ...] of the value names
union an alias of Union[...] of the members
String, ID, Int, Float, Boolean str, str, int, float, bool
any other scalar Any

Types are written in IR order, except that a union alias moves to just after the last of its members: a type checker reads A = 'B' as a string, not as an alias, and Python 3.9 has no typing.TypeAlias. A reference to a type written later, inside a field or a subscript such as List['B'], is a string forward reference, so the module imports.

The syntax API

Other targets build modules with the syntax API and print them with render. Optional keys, keys that are Python keywords and Literal values all work on Python 3.9.

from wesley_python.syntax import Field, Module, TypedDictDef, render
from wesley_python.types import Int, Literal, Ref

module = Module(
    [
        TypedDictDef(
            "Window",
            [
                Field("from", Int(), required=True, doc="The first line, inclusive."),
                Field("to", Int(), required=False),
            ],
            doc="A range of line numbers.",
        ),
        TypedDictDef(
            "End",
            [
                Field("event", Literal("end"), required=True),
                Field("window", Ref("Window"), required=False),
            ],
        ),
    ]
)
print(render(module), end="")

prints, exactly as ast.unparse lays it out,

from typing import Literal, TypedDict
_WindowRequired = TypedDict('_WindowRequired', {'from': int})
_WindowOptional = TypedDict('_WindowOptional', {'to': int}, total=False)

class Window(_WindowRequired, _WindowOptional):
    """A range of line numbers.

    from: The first line, inclusive.
    """
_EndRequired = TypedDict('_EndRequired', {'event': Literal['end']})
_EndOptional = TypedDict('_EndOptional', {'window': Window}, total=False)

class End(_EndRequired, _EndOptional):
    pass
  • wesley_python.types: Str(), Int(), Float(), Bool(), AnyValue(), NoneType(), Literal(value) for a str, int or bool, ListOf(item), DictOf(value) (string keys), Ref(name) for a type the module defines, and UnionOf(*members). A union of one member prints as that member, and a union of literals prints as one Literal[...].
  • wesley_python.syntax: Field(name, type, required, doc=None), TypedDictDef(name, fields, doc=None), AliasDef(name, type, doc=None), Module(definitions, doc=None), to_ast(module) returning the ast.Module, and render(module) returning its source, ending in one newline.

How a TypedDict is written: typing.NotRequired is new in Python 3.11, and the class syntax cannot name a key such as from. So the required keys and the optional keys are each a functional-form TypedDict, the optional one total=False, and the class inherits from both; a side with no keys is left out, and a definition with no keys inherits from TypedDict. ast.unparse cannot print comments, so field docs go into the class docstring as a name: doc list, and an alias's doc is a string statement after it. The from typing import ... line names exactly the names used, sorted.

The caller orders the definitions; render keeps the given order. A reference to a later definition is a string forward reference, which is allowed inside a field type or a subscript but not as the whole type of an alias: AliasDef('Result', Ref('Item')) before Item is a ValueError naming both. An alias whose whole type is None is written Name = Literal[None], because Name = None binds a value rather than an alias. A definition name must be a Python identifier; two definitions may not bind the same name (including the _NameRequired and _NameOptional helpers), and a definition may not shadow a typing or builtin name the module uses. These are ValueErrors.

Development

uv venv -p 3.9 .venv && uv pip install -p .venv -r requirements-dev.txt
git config --local core.hooksPath scripts/hooks
PYTHONPATH=src .venv/bin/python -m unittest discover -s tests -t .
.venv/bin/ruff check . && .venv/bin/ruff format --check . && .venv/bin/mypy

requirements-dev.txt pins mypy, ruff, build and twine exactly; they are development tools, not dependencies. The pre-commit hook runs ruff and mypy, and the pre-push hook runs the test suite. CI runs all of it on Python 3.9 and 3.13. It also builds the sdist and wheel, checks them with twine check --strict and for LICENSE and NOTICE, and installs the wheel into fresh environments to run it (scripts/check-dist).

Releases are made by pushing an annotated tag; RELEASING.md describes the procedure.

The goldens under tests/golden/ are compared byte for byte, compiled with py_compile, imported, and type-checked by mypy --strict --python-version 3.9 together with the fixtures under tests/typecheck/: the good uses must pass and each bad_*.py must fail with its expected error (a wrong event literal, a keyword key read as the wrong type, a missing required key). To rewrite the goldens after an intended change, run the suite with WESLEY_PYTHON_UPDATE_GOLDENS=1 and review the diff.

Where it comes from

The plan is issue #1 (transferred from flyingrobots/wesley#858). Its first consumer is Parley's vendorable Python writer (flyingrobots/parley#121).

How it generates code

The output is built as a syntax tree of the target language and printed by that language's printer. There is no string templating and no regex anywhere in the generator.

Concern Choice
Written in Python 3.9 or later, standard library only
Syntax tree the standard library ast module
Printer ast.unparse
Checked by py_compile and a static type checker on every golden module, on the oldest and newest supported Python

Rules every change keeps:

  • No code as strings. A generated identifier, literal or comment enters the output as a node of the tree, never by concatenating source text. Escaping is the printer's job.
  • Golden output is checked by the real toolchain. Every golden file is compiled or type-checked in CI by the toolchain named above, not only compared byte for byte.
  • Deterministic to the byte. The same IR and options give the same bytes on every machine. CI runs the generator twice and compares.
  • The IR is the only input. The target reads the published IR (flyingrobots/wesley#881) and never depends on Wesley's internals.

License

Apache 2.0. See LICENSE and NOTICE.

Metadata

Release files for wesley-python 0.1.0a1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for wesley-python 0.1.0a1
File Size Uploaded Provenance Actions
wesley_python-0.1.0a1.tar.gz 22.3 kB With provenance Details for wesley_python-0.1.0a1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for wesley-python 0.1.0a1
File Interpreter ABI Platform Actions
wesley_python-0.1.0a1-py3-none-any.whl Python 3 none any Details for wesley_python-0.1.0a1-py3-none-any.whl

Total release size: 43.2 kB

Release files / wesley_python-0.1.0a1.tar.gz

Download URL wesley_python-0.1.0a1.tar.gz
Size 22.3 kB
Tags Source
SHA-256 checksum
How to use checksums
bd924437bb495ec140b2942049d8290564f8dad2d3f2948fe6093f53c926340a
BLAKE2b-256 checksum
How to use checksums
10d565894a47f346a73f370ba092e02d2fc9846f2f80c90075bf44aaab4cc8fd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

Release files / wesley_python-0.1.0a1-py3-none-any.whl

Download URL wesley_python-0.1.0a1-py3-none-any.whl
Size 20.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
eb2f180c54b2ba91054e6c8f26de83a7436f0c614bb7f9182a74717013258d7d
BLAKE2b-256 checksum
How to use checksums
12778185253aade067dda68a80790406204c32d81fad847f2d754992f33b6a51
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

Security for wesley-python 0.1.0a1

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for wesley_python-0.1.0a1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

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.

Release history Release notifications | RSS feed

This release
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