Command line interface (cli) boilerplate using a schema
Project description
Create a command line interface with minimal setup.
Command line interface (Cli) with a schema (Ma) - Clima
Installation
pip install clima
Requires Python 3.9.2+.
Quick example
from clima import Schema
class S(Schema):
place = 'Finland'
@S.cli
class Cli:
def say_hi(self):
print(f'Hi from {S.place}')
$ cli.py say_hi
Hi from Finland
$ cli.py say_hi --place 'Sweden'
Hi from Sweden
Why Clima?
Clima eliminates CLI boilerplate: just define a Schema dataclass and a Cli class. Opinionated for convenience; Unlike click, typer, or argparse, clima gives you a built-in config cascade (CLI args → env vars → .env file → config file → defaults) with zero extra code.
Features
Schema fields double as CLI flags, environment variables, and config file keys automatically while providing help printout, default values and type casting.
- Config cascade :: CLI args → env vars →
.envfile → config file → defaults, resolved automatically - Type casting :: Schema field annotations are used to cast string CLI/env values to the right type
- Help from field comments :: Docstrings on Schema fields act as
--helpoutput - IDE completions ::
C.nameis typed asstr— completions and type checking work natively --verbose/--quietlogging :: Addverbose: boolorquiet: boolto Schema and get preconfigured logging- Undefined param warnings :: Unknown
--flagson the command line produce a clear warning versionsubcommand ::myscript versionprints the package version automatically- Config file support :: Declare defaults in an INI-style
.conffile keyed to your package name .envfile and env var support :: Schema fields are also read from environment variables and.envfiles- Optional gpg secrets :: Decrypt secrets via
pass/ gnupg if installed - Optional shortened tracebacks :: Truncate python tracebacks into an opinionated format
Documentation
Full documentation at python-clima.readthedocs.io.
See and run the examples/ directory for more usage patterns.
AI Disclaimer
This work started in 2019 as my hobby project and continues as so. Claude was used to bridge gaps I had planned, but had not had the time to address.
Before merging to main and uploading to pypi the code is hand-vetted to find all code assistance related issues.
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 clima-0.13.8.tar.gz.
File metadata
- Download URL: clima-0.13.8.tar.gz
- Upload date:
- Size: 38.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.4.0 CPython/3.12.9 Darwin/24.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5a438d6aa59f70888122bdf131af011c053d22c827fc144cede678686c27de5a
|
|
| MD5 |
03adc360177ba2ccfe553c9f88db87cd
|
|
| BLAKE2b-256 |
79602fb36b24f2ca05c072bd33b4b1563ad9c0ec00aa3f0d46e96aeb65930e00
|
File details
Details for the file clima-0.13.8-py3-none-any.whl.
File metadata
- Download URL: clima-0.13.8-py3-none-any.whl
- Upload date:
- Size: 48.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.4.0 CPython/3.12.9 Darwin/24.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e176ec076fedf2864ca004c981d32ff8f590b069b910f3a3df56c543af3224d2
|
|
| MD5 |
50e4f1014ce36fedece5c76c3dd4a5e6
|
|
| BLAKE2b-256 |
dc908df3f1a09a8dcae1a5a4c873e0bfb5b2705a786b3cbf88554dc1b5dbde09
|