Skip to main content

Create click option fields from pydantic models. Inspired by felix-martel/pydanclick.

Project description

Pydanclick (but-different)

Release Build status License

Generate Click options from Pydantic models

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-but-different

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pydanclick_but_different-0.1.1.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

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

pydanclick_but_different-0.1.1-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file pydanclick_but_different-0.1.1.tar.gz.

File metadata

  • Download URL: pydanclick_but_different-0.1.1.tar.gz
  • Upload date:
  • Size: 3.6 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

Hashes for pydanclick_but_different-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d47da2610fc9448b7c6b1618e9973b826092eebf935599656931f16ba43df1e2
MD5 4cbf3bcdc83f89a7eda35f4dfda14e06
BLAKE2b-256 1dc297c2ec5476850401500d5343af44de67141467681803141be3c9f59cca9e

See more details on using hashes here.

File details

Details for the file pydanclick_but_different-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: pydanclick_but_different-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.0 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

Hashes for pydanclick_but_different-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4eb6c8aaedd0f3900f792141710a5028bfb5166ec51b2fd39729265ff74225f3
MD5 ffe4ca85f5ee3f451e685e26d63b707f
BLAKE2b-256 ef154b7acc49923266317ab5a5beae49b813b4bb77a857004fd9fe0b2f6fce54

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