Create a command line interface with minimal setup.
pip install clima
Requires Python 3.9.2+.
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
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.
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 toml
.tomlor 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
Full documentation at python-clima.readthedocs.io.
See and run the examples/ directory for more usage patterns.
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.
