Skip to content

coloco-kit/type-less

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Type-Less PyPI

Type Less

Find yourself typing less with automatic type inference for Python! Inject function return types at runtime for code generation 🤙.

FastAPI Example

class User:
    id: int
    first: str
    last: str

@app.get("/user/me")
def user_me(user: User):
    return {
        "id": user.id,
        "balance": 13.37,
        "name": {
            "first": user.first,
            "last": user.last,
        },
    }

🚀 Generates Return Types:

class UserMeName(TypedDict):
    first: str
    last: str

class UserMe(TypedDict):
    id: int
    balance: Literal[13.37]
    name: UserMeName

📋 OpenAPI Spec:

OpenAPI Example

Using in FastAPI Project

Inject types before by hooking before setting up routes. Types will be automatically generated when new routes are added.

from type_less.inject import inject_fastapi_route_types
from fastapi import FastAPI

app = FastAPI()
app = inject_fastapi_route_types(app)

@app.get("/test")
def test(request):
    ...

Testing

  • uv run pytest

TODO:

Add Support:

  • Nested class inference
  • Deep function call / return inference

Better Way?:

  • Possibly use pyright, pyre, mypy, or anything else to infer the type?

Cleanup:

  • Possibly refactor - a large portion of the initial work was codegen from claude and has patterns that need rethinking of proper documentation

About

Type less with automatic type inference for Python

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages