Use [pydantic](https://docs.pydantic.dev/latest/) to manage persistent config for your [Typer](https://typer.tiangolo.com/) CLI apps!
Project description
Typer Pydantic Config
This package helps you quickly build python CLI applications with a persistent config using typer & pydantic.
See minimal.py and example.py for two simple examples.
Installation
Install it from pypi using your preferred method, e.g. through uv:
uv pip install typer-pydantic-config
Usage
- Implement config object as pydantic class
- Use
get_configwhere every you need the config object - Build your typer app
- Start the app with
start_config_app(app, <YourConfigPydanticClass>)
On the first invocation, prompts the user to set all values in the config file.
Your app now has an additional config command with the following signature:
$ python example.py config --help
Usage: example.py config [OPTIONS] COMMAND [ARGS]...
Interact with config: (delete | init | path | set | show).
Options:
--help Show this message and exit.
Commands:
delete Delete config file on disk.
init Interactively prompt for every field in the config.
path Print config path.
set Set one or more config fields via flags.
show Print content of config file.
⚠ Current Limitations ⚠
- The package is still an early draft and not yet thoroughly tested
- Does not support
default_factoryyet - Does not support optional fields yet
- The following types are supported as attributes of your config class:
- int
- float
- bool
- str
- datetime
- Path
- another subclass of pydantic's
BaseModel
- Config values are available as
ctx.obj["config"](see click docs: Context).- This is only available when one of the endpoint functions is called.
- Do not overwrite the
ctx.obj(at least not the"config"key).
- Unique app name required:
- Set a unique name:
app = typer.Typer(name="<some_unique_name>") - This name is used by platformdirs to construct the path of the config.
- Set a unique name:
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
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 typer_pydantic_config-0.4.0.tar.gz.
File metadata
- Download URL: typer_pydantic_config-0.4.0.tar.gz
- Upload date:
- Size: 22.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c53df531de82b1a845926533dd7f80c7470a5585ff0ba6b5ff60e0298a8efdeb
|
|
| MD5 |
62d45681f31dcf5335508d612fe604db
|
|
| BLAKE2b-256 |
1b0dba4d76dbafe362a1a9c95ae4fe51f2da258a99788bc7a78a19c1a4e0e528
|
File details
Details for the file typer_pydantic_config-0.4.0-py3-none-any.whl.
File metadata
- Download URL: typer_pydantic_config-0.4.0-py3-none-any.whl
- Upload date:
- Size: 9.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e6b52db5de1f211b638eb88fd42d3df1044cecf527680ddca792b2017e4450f5
|
|
| MD5 |
4df3e2440198facc5d333c6b7a3f258c
|
|
| BLAKE2b-256 |
60fbed4ea078795e794d90e2371e3fbebe0beccebb1d9fd1166011e0dc8bb0e5
|