Skip to content

basedpython

a python-like language that transpiles to pure python — sum types, extensions, optional chaining and a type system that knows what your code means, lowered to files any python tool can read

  • a python type checker with framework support — pydantic, sqlalchemy, pytest and django are modelled directly, so the magic they do at runtime checks like ordinary code
  • polyfill and transpilation — write code against the latest version of python, and ship wheels that are compatible with old ones, no more waiting for 5 years to use new features
  • basedpython-language — based on Python, powerful and modern. fully backwards compatible
  • compiles into high performance python extension modules — or ordinary Python
  • a language server, formatter and linter — high performance and feature rich tooling
enum class Shape:
    case Circle(radius: int)
    case Rect(width: int, height: int)

    def area(self) -> int:
        return match self:
            case Shape.Circle(r):
                3 * r * r
            case Shape.Rect(w, h):
                w * h

extension list[Element: Shape]:
    def first_circle(self) -> Shape.Circle?:
        for shape in self:
            if shape is Shape.Circle:
                return shape
        return None

def stats(shapes: list[Shape]) -> (count: int, total: int):
    return (len(shapes), sum(s.area() for s in shapes))

def main():
    let shapes = [Shape.Circle(1), Shape.Rect(2, 3)]
    let summary = stats(shapes)
    print(f"{summary.count} shapes, {summary.total} total")
    print(shapes.first_circle()?.radius ?? 0)

why

Wouldn't it be nice if you could say protocol C: instead of having to write:

from typing import Protocol

class C(Protocol):

- Guido van Rossum

Python and its type system are held back due to an inability to make breaking changes and a hesitation to introduce new syntax

other languages have indulged in modern features, powerful type systems, and integrated tooling. we want to close that gap

what you get

  • plain python out the other end


    by build writes ordinary .py files. pytest, mypy, ruff and everything else in your stack keep working, because what they see is python

    how to build

  • syntax python doesn't have


    sum types with payloads, extension methods, destructuring, trailing lambda blocks, ?., ??, and properties that read like declarations

    the language reference

  • a type system that keeps up


    intersections, negations, match types, symbolic arithmetic in type parameters, and inference that narrows instead of shrugging

    type system features

  • frameworks understood, not tolerated


    pydantic, sqlalchemy, pytest and django are modelled directly, so synthesized constructors and injected fixtures check like real code

    framework support

where to go

credits for contributors and the third-party work basedpython relies on