Skip to main content

No project description provided

Project description

typegen Is a Typed Dict Generator

Auto generate typed dicts.

What it works for?

  • Basic dictionaries
  • Nested dictionaries
  • Dictionaries with Lists if the items are of same type
  • Any level of nesting as long as list items are of same type
  • None values default to Optional[Any]

Usage:

usage: typegen [-h] -f FILE -v VAR -t TYPE_NAME [-o OUTPUT]

Import a variable from a file.

options:
  -h, --help            show this help message and exit
  -f FILE, --file FILE  Path to the python file (without .py extension)
  -v VAR, --var VAR     Variable name in the file
  -t TYPE_NAME, --type-name TYPE_NAME
                        Name for the type
  -o OUTPUT, --output OUTPUT
                        Path to the output file (default: out/<name of variable>.py)

Example:

File: tests/fish_obj.py
fish = {
    'fish': {
        "health":3,
        "location":{
            "city": "belo",
            "state": "kansas"
        },
        "items": [{"item_id": 1, "value":4, "name": "scales", "variations": ["weak", "strong"]}, {"item_id": 2, "value":4, "name": "knife", "variations": ["weak", "strong"]}, {"item_id": 1, "value":4, "name": "scales", "variations": ["weak", "strong"]}   ]
        
    }
}

Run

typegen -f tests/fish_obj -v fish -t FishType

Output:

File: out/FishType.py
from typing import TypedDict, List, Optional, Any

class ItemsList(TypedDict):
    item_id: int
    value: int
    name: str
    variations: List[str]

class Location(TypedDict):
    city: str
    state: str

class Fish(TypedDict):
    health: int
    location: Location
    items: List[ItemsList]

class FishType(TypedDict):
    fish: Fish

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

typegen-0.1.0.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

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

typegen-0.1.0-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file typegen-0.1.0.tar.gz.

File metadata

  • Download URL: typegen-0.1.0.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.10.12 Linux/5.15.90.1-microsoft-standard-WSL2

File hashes

Hashes for typegen-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f530bc53f8bbd580a1513be92920ed1bae065d68d6a7abd5db4f28be0635ece9
MD5 f93775df275144b0c6496f581521164a
BLAKE2b-256 fef526744d3093acb0f070291c718203a8c3663ebac6a51821a3cc15a61edf63

See more details on using hashes here.

File details

Details for the file typegen-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: typegen-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.10.12 Linux/5.15.90.1-microsoft-standard-WSL2

File hashes

Hashes for typegen-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1cfd8b05ecea6fa9e63a0f192ea54cb6fc9371b8984ab57a2de2384a12749a46
MD5 2f443088c9c1b7cf40fbd660fb83e48b
BLAKE2b-256 0e91485448377a539fd9387d1f6e9508a9db8e090dba778de7026872c8493966

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