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.27.tar.gz (72.9 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.27-py3-none-any.whl (12.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: type_less-0.1.27.tar.gz
  • Upload date:
  • Size: 72.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: pdm/2.25.4 CPython/3.13.5 Linux/6.11.0-1018-azure

File hashes

Hashes for type_less-0.1.27.tar.gz
Algorithm Hash digest
SHA256 c63d741e7a3f62c4191cedae2889ec8d337d7ad8b52941a396c0c37b6c34ec90
MD5 9dd8017db28cad821b8d368c6a32fe1e
BLAKE2b-256 c05591d9a4b2d336549b6913bdb2ea45ee7d1b779bc53ca75eee022ba85a8ffe

See more details on using hashes here.

File details

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

File metadata

  • Download URL: type_less-0.1.27-py3-none-any.whl
  • Upload date:
  • Size: 12.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: pdm/2.25.4 CPython/3.13.5 Linux/6.11.0-1018-azure

File hashes

Hashes for type_less-0.1.27-py3-none-any.whl
Algorithm Hash digest
SHA256 cbbbe4fb8c61f96ea92fe33f0e70f8a068373e7f83a67a52f1b3343fc74eb51a
MD5 c592ab2674aa555fbaf06cfed320d5d8
BLAKE2b-256 9fe6036305ee89e293c983d47b524717d9368c2e133a1276e59a115d1cb7f8e4

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