engorgio
![](https://private-user-images.githubusercontent.com/22648375/243203758-e2577efd-cb4b-417a-8139-ef2a7d75c8d9.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MDg3OTk5NTAsIm5iZiI6MTcwODc5OTY1MCwicGF0aCI6Ii8yMjY0ODM3NS8yNDMyMDM3NTgtZTI1NzdlZmQtY2I0Yi00MTdhLTgxMzktZWYyYTdkNzVjOGQ5LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDAyMjQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwMjI0VDE4MzQxMFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTdiYmQwM2IyYTVjOTdhYmQwYTY2NTViYTBhMGNhN2ZiMmJjNTMyYTViNGVjNmE5Mzg5MGJiY2E3NjQ0ZWZhMGUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.Y55wPrb7HBZOZARulj5e_NFQfOrmi2VD6btTg3fqzuc)
Expands function arguments into fields.
pydantic-typer.mp4
Installation
pypi package to come if this works out, and I can decide what to call it. I think its possible to do this for other objects like dataclasses as well.
pip install git+https://github.com/WaylonWalker/engorgio.gi
Usage
Setup your models.
from typing import Optional
from pydantic import BaseModel, Field
class Alpha(BaseModel):
a: int
class Color(BaseModel):
r: int
g: int
b: int
alpha: Alpha
class Hair(BaseModel):
color: Color
length: int
class Person(BaseModel):
name: str
other_name: Optional[str] = None
age: int
email: Optional[str]
pet: str = "dog"
address: str = Field("123 Main St", description="Where the person calls home.")
hair: Hair
Now create a typer command using your models.
engorgio
will expand all of the typer fields
for you.
import typer
from engorgio import engorgio
app = typer.Typer(
name="engorgio",
help="a demo app",
)
@app.command()
@engorgio
def get_person(person: Person) -> Person:
"""Get a person's information."""
from rich import print
print(person)
Get the help message.
engorgio get-person --help
Usage: engorgio get-person [OPTIONS]
Get a person's information.
╭─ Options ──────────────────────────────────────────────────────────────────────────────╮
│ --help Show this message and exit. │
╰────────────────────────────────────────────────────────────────────────────────────────╯
╭─ Person ───────────────────────────────────────────────────────────────────────────────╮
│ * --name TEXT [default: None] [required] │
│ --other-name TEXT [default: None] │
│ * --age INTEGER [default: None] [required] │
│ --email TEXT [default: None] │
│ --pet TEXT [default: dog] │
│ --address TEXT Where the person calls home. [default: 123 Main St] │
╰────────────────────────────────────────────────────────────────────────────────────────╯
╭─ Person.Hair ──────────────────────────────────────────────────────────────────────────╮
│ * --length INTEGER [default: None] [required] │
╰────────────────────────────────────────────────────────────────────────────────────────╯
╭─ Person.Hair.Color ────────────────────────────────────────────────────────────────────╮
│ * --r INTEGER [default: None] [required] │
│ * --g INTEGER [default: None] [required] │
│ * --b INTEGER [default: None] [required] │
╰────────────────────────────────────────────────────────────────────────────────────────╯
╭─ Person.Hair.Color.Alpha ──────────────────────────────────────────────────────────────╮
│ * --a INTEGER [default: None] [required] │
╰────────────────────────────────────────────────────────────────────────────────────────╯
Calling the cli will print out a Person object.
engorgio get-person --name me --age 1 --r 1 --g 1 --b 1 --a 1 --length 1
Calling the cli while not specifying required arguments will automatically prompt for them.
engorgio get-person
License
engorgio
is distributed under the terms of the MIT license.