Skip to main content

Type less types with inferred return types

Project description

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

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_less-0.1.28.tar.gz (77.7 kB view details)

Uploaded Source

Built Distribution

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

type_less-0.1.28-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

Details for the file type_less-0.1.28.tar.gz.

File metadata

  • Download URL: type_less-0.1.28.tar.gz
  • Upload date:
  • Size: 77.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: pdm/2.27.0 CPython/3.14.5 Linux/6.17.0-1015-azure

File hashes

Hashes for type_less-0.1.28.tar.gz
Algorithm Hash digest
SHA256 08b2a229b3cc0aec28940c398699c8c13d85de92e11badea70b67b359d6c94d9
MD5 c4d4c6195d095b3161ec2000b2c5f9b7
BLAKE2b-256 c2eac56df22ea74fdc033877e1360ad0c5be8a53053f35dc63c472e2de7da86e

See more details on using hashes here.

File details

Details for the file type_less-0.1.28-py3-none-any.whl.

File metadata

  • Download URL: type_less-0.1.28-py3-none-any.whl
  • Upload date:
  • Size: 12.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: pdm/2.27.0 CPython/3.14.5 Linux/6.17.0-1015-azure

File hashes

Hashes for type_less-0.1.28-py3-none-any.whl
Algorithm Hash digest
SHA256 12a1fa43a57cdb41bd38fe0c1264a9726534090d4d616ddcbc4bfaab6ebe8d08
MD5 95224269776abbc345af3b733e6fe4c1
BLAKE2b-256 40d5c7a19d8ad3fd812f20c11fd768582b594ddbd8303c571b59656c86306f16

See more details on using hashes here.

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