Create click option fields from pydantic models. Inspired by felix-martel/pydanclick.
Project description
Pydanclick (but-different)
Inspired by the original (and fantastic) Pydanclick by Felix Martel, writen from scratch without the use of AI.
Differences from Pydanclick
- Uses Field extra data for overrides, rather than passing through the decorator
- Written by Sam Laird as opposed to Felix Martel
Yet to be implemented/TODO
- Nested Model
- Object Unpacking
- Validation/testing
Installation / Basic Usage
Install via pip/uv/your_package_manager_of_choice
pip install pydanclick-bd
To then use simply call the pydantic_option decorator with your pydantic model, on a click endpoint
from pydanclick-bd import pydantic_option
class MyEnum(Enum):
RedPill = auto()
BluePill = auto()
class MyModel(BaseModel):
foo: str = Field(description="Help string goes here. Foo is optional since it has a default", default="Bazinga")
bar: int = Field(description="Gt/lt operators are supported", gt=69, le= 420)
choice: MyEnum = Field(description="Enums are converted to choice options. Anything can be prompted with prompt", prompt=True)
hidden: int = Field(description="This will not be shown in help", hidden=True)
shit: bool = Field(description="Alias' are also supported", validation_alias="poop")
@click.command()
@pydantic_option(MyModel)
@pydantic_option(MyOtherModel, 'named_something_unique')
def cli(mymodel: MyModel, named_something_unique: MyOtherModel):
# your click method here
...
~ python click_app.py --help
Usage: click_app.py [OPTIONS]
Options:
--poop BOOLEAN Alias' are also supported [required]
--choice [RedPill|BluePill] Enums are converted to choice options. Anything
can be prompted with prompt [required]
--bar INTEGER RANGE Gt/lt operators are supported [69<x<=420;
required]
--foo TEXT Help string goes here. Foo is optional since it
has a default
--help Show this message and exit.
Details
Supported types
| Field Type | Passed as |
|---|---|
bool |
click.BOOL |
str |
click.STRING |
int |
click.INT |
float |
click.FLOAT |
pathlib.Path |
click.Path() |
UUID |
click.UUID |
datetime, date |
click.DateTime() |
Enum |
click.Choice |
Supported Field Flags
| Field(...) parameter | Description |
|---|---|
description |
Help string |
required |
Explicitly mark field as required (default) |
alias, validation_alias |
Use as Option name |
hidden |
Hide field from help message |
default |
Default value/mark un-required |
gt/ge/lt/le |
Use specified range (Note, this passes as <int|float>Range()) |
prompt |
Prompt user for input if option is not provided. |
hide_input |
Hide's user input if prompted (password mode) |
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pydanclick_but_different-0.1.0.tar.gz.
File metadata
- Download URL: pydanclick_but_different-0.1.0.tar.gz
- Upload date:
- Size: 3.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1130df70a8a35cf9d86c470ce0d9394abb368085ac1af805bce90f9ad6ed578d
|
|
| MD5 |
92066025d82928a6a8c8c6771cb1db5c
|
|
| BLAKE2b-256 |
8ab3510faeec3d63428e907d5c1abeaa44f89a6a9fcc8e786e5f88bcefb877b8
|
File details
Details for the file pydanclick_but_different-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pydanclick_but_different-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2cf4bf239e1afb9e7e51fcff939700c621ad8e8c1a5b5c7a2be577d76dd716b2
|
|
| MD5 |
c7a7188a5ea081a3e04957ba19c3cb58
|
|
| BLAKE2b-256 |
355a8cc3e86558b18d0c3306977d0d4780bd1af3d9940b9e02f4f7c96bdb969d
|