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
  • basedpython, a python-like language that builds into python wheels
  • compiles into high performance python extension modules
  • a language server, formatter and linterby server drives the editor, and buff is the basedpython build of ruff
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)

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 transpilation works

  • 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