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:- 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 buildwrites ordinary.pyfiles. pytest, mypy, ruff and everything else in your stack keep working, because what they see is python -
syntax python doesn't have
sum types with payloads, extension methods, destructuring, trailing lambda blocks,
?.,??, and properties that read like declarations -
a type system that keeps up
intersections, negations, match types, symbolic arithmetic in type parameters, and inference that narrows instead of shrugging
-
frameworks understood, not tolerated
pydantic, sqlalchemy, pytest and django are modelled directly, so synthesized constructors and injected fixtures check like real code
where to go¶
-
install, your first
.byfile, project layout, and wiringby buildinto CI -
the full language reference, one page per feature
-
where settings live and how they resolve
-
what basedpython knows about pydantic, sqlalchemy, pytest and django
-
every place the same source means something different in a
.byfile -
every command and flag the
bydriver adds
credits for contributors and the third-party work basedpython relies on