Skip to main content

A statically-typed authoring language that compiles to standard Python

Project description

TypePython

TypePython

Write richer types in .tpy. Ship plain .py + .pyi.


TypePython is a typed dialect of Python that compiles to standard .py + .pyi. It brings TypeScript-class ergonomics — sealed classes, exhaustive match, strict null checks, unknown, interface, data class — to a language whose output runs anywhere CPython runs.

No custom runtime. No per-checker plugin. No vendor lock-in.

Status: alpha (v0.3.0). The compiler core, type checker, and LSP are stable; framework adapters and runtime validators are in prototype. Bug reports and contributions are very welcome.

Install

pip install type-python
typepython init --dir hello && cd hello
typepython check --project .
typepython build --project .

You now have .typepython/build/ with .py + .pyi + py.typed ready for any Python interpreter, IDE, or downstream type checker.

  • Wheels are prebuilt for Windows AMD64, macOS x86_64, macOS arm64, and Linux x86_64. Other platforms fall back to source and need Rust + cargo.
  • Python: the package bridge supports 3.9+; generated projects target Python 3.10 through 3.14.

See it in 15 lines

# src/app/expr.tpy

sealed class Expr:
    pass

class Num(Expr):  value: int
class Add(Expr):  left: Expr; right: Expr
class Neg(Expr):  operand: Expr

def evaluate(expr: Expr) -> int:
    match expr:
        case Num(value=v):           return v
        case Add(left=l, right=r):   return evaluate(l) + evaluate(r)
        case Neg(operand=o):         return -evaluate(o)
    # No default branch needed — the compiler proves the match is exhaustive.
    # Add a fourth subclass and TypePython tells you exactly where to update.

typepython build lowers that to ordinary Python and writes a matching .pyi that any modern type checker can consume — no TypePython runtime required.

What you write vs. what ships

You write (.tpy) TypePython emits (.py / .pyi)
interface Drawable: class Drawable(Protocol):
data class User: @dataclass class User:
sealed class Expr: ordinary class + tpy:sealed marker
overload def parse(...) @overload def parse(...)
typealias Pair[T] = tuple[T, T] T = TypeVar("T") + Pair: TypeAlias = tuple[T, T]
def first[T](xs: list[T]) -> T: inline generic on 3.13+, TypeVar-based on 3.10 – 3.12
unsafe: eval(expr) valid Python, marker erased — runtime behavior preserved
unknown (must narrow before use) object in .pyi
Partial[Config] / Pick[Config, …] expanded TypedDict shapes (PEP 655 / 705)

Why not just mypy / pyright / PEP 695?

Capability mypy strict pyright strict PEP 695 .py TypePython .tpy
sealed class + compiler-proved exhaustiveness
unknown — safe dynamic boundary, must narrow
unsafe: audit fence for eval / exec / setattr
First-class interface / data class / typealias via via via keyword
Inline generics def f[T] on any target ≥ 3.10 3.12+ 3.12+ 3.12+
TypedDict transforms (Partial, Pick, Readonly…)
Output consumed by mypy / pyright / ty unmodified N/A N/A

TypePython doesn't replace those checkers. It sits one step earlier: you author in .tpy, the compiler emits standard typed Python that those tools then consume normally.

What you also get

  • Rust-native, incremental compiler — public-API fingerprints skip downstream rechecks when only a body changes.
  • Full toolchaininit, check, build, watch, clean, verify, compat, api-diff, type-health, migrate, lsp.
  • LSP server — hover, go to definition, references, rename, completions, signature help, real-time diagnostics, and code-action quick fixes. Bring your own LSP-capable editor (VS Code, Neovim, Helix, Sublime, Emacs).
  • Standard, portable output — emitted .py + .pyi work with mypy, pyright, and ty out of the box. PEP 561 py.typed is written automatically.
  • Mixed projects.tpy, .py, and .pyi live in the same source tree. .py is pass-through; .pyi is stub-authoritative.

For library authors

Five commands aimed at people who publish typed Python:

typepython build       --project .
typepython verify      --project . --checker-preset all
typepython compat      --project . --profile library-portable
typepython api-diff    dist/previous.whl .typepython/build
typepython type-health --project . --fail-under 85

These catch missing/stale py.typed, wheel ↔ build-tree drift, multi-checker portability gaps, public-API drift between releases, and runtime-annotation hazards for frameworks that introspect annotations.

Documentation

Links

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

type_python-0.3.1.tar.gz (1.0 MB view details)

Uploaded Source

Built Distributions

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

type_python-0.3.1-py3-none-win_amd64.whl (5.0 MB view details)

Uploaded Python 3Windows x86-64

type_python-0.3.1-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (5.1 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64

type_python-0.3.1-py3-none-macosx_11_0_arm64.whl (4.5 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

type_python-0.3.1-py3-none-macosx_10_13_x86_64.whl (4.9 MB view details)

Uploaded Python 3macOS 10.13+ x86-64

File details

Details for the file type_python-0.3.1.tar.gz.

File metadata

  • Download URL: type_python-0.3.1.tar.gz
  • Upload date:
  • Size: 1.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for type_python-0.3.1.tar.gz
Algorithm Hash digest
SHA256 b9799bb8cf5d49a23f853910f71f4b0b15ae56a5f4c47a28ba9b5e25b8ee4787
MD5 3561953e4930d82bf1b4e87ea9def3fb
BLAKE2b-256 e76e928e738239d26088a22de34ebdff94732122078209572fa1a897de03c0ad

See more details on using hashes here.

Provenance

The following attestation bundles were made for type_python-0.3.1.tar.gz:

Publisher: publish.yml on type-python/type-python

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

File details

Details for the file type_python-0.3.1-py3-none-win_amd64.whl.

File metadata

  • Download URL: type_python-0.3.1-py3-none-win_amd64.whl
  • Upload date:
  • Size: 5.0 MB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for type_python-0.3.1-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 71e714aa73b75a00aad5ac7ecee93b8c4d86819d865ed477015f06077f8b6b24
MD5 bf511f729162b7e81343167048111711
BLAKE2b-256 60a7a6005938638310a6eba6a60e5ac4a1744ed43f434f756f9d17577d00234d

See more details on using hashes here.

Provenance

The following attestation bundles were made for type_python-0.3.1-py3-none-win_amd64.whl:

Publisher: publish.yml on type-python/type-python

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

File details

Details for the file type_python-0.3.1-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for type_python-0.3.1-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 7bbf09a07a9e1168a0b4693d356fb4621efdcfba29a1504ccd873c1024d314c9
MD5 b7bc89e044881706d641b810e428274f
BLAKE2b-256 bc6bf6362f5af29d07c6689ceccaa0147ac26f4e4b390e6a581a746d83b5f450

See more details on using hashes here.

Provenance

The following attestation bundles were made for type_python-0.3.1-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl:

Publisher: publish.yml on type-python/type-python

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

File details

Details for the file type_python-0.3.1-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for type_python-0.3.1-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3f285b24c6075bab92856902e43f11fd9664374a74a14ad964200b2a4a6e4c05
MD5 0218c1d467444be8cd4bf62b74ce0865
BLAKE2b-256 0d467d96fb9e3e3c82d3660ecdac089a2fdf79c19f3c9ab3c27bc8aece825f28

See more details on using hashes here.

Provenance

The following attestation bundles were made for type_python-0.3.1-py3-none-macosx_11_0_arm64.whl:

Publisher: publish.yml on type-python/type-python

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

File details

Details for the file type_python-0.3.1-py3-none-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for type_python-0.3.1-py3-none-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 a54f19693648135951c9a6f356816a821e2272a06690e8f9e99a02b32c53a1b0
MD5 b3375176a9fa70cec3af14a10a208c7b
BLAKE2b-256 e43881a6412c77e9032c5bc329b24baea2da85f25782aef894f9b2a4f705582a

See more details on using hashes here.

Provenance

The following attestation bundles were made for type_python-0.3.1-py3-none-macosx_10_13_x86_64.whl:

Publisher: publish.yml on type-python/type-python

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