Skip to main content

Command line interface (cli) boilerplate using a schema

Project description

Create a command line interface with minimal setup.

PyPI Python versions PyPI license

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 → .env file → 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 --help output
  • IDE completions :: C.name is typed as str — completions and type checking work natively
  • --verbose / --quiet logging :: Add verbose: bool or quiet: bool to Schema and get preconfigured logging
  • Undefined param warnings :: Unknown --flags on the command line produce a clear warning
  • version subcommand :: myscript version prints the package version automatically
  • Config file support :: Declare defaults in an INI-style .conf file keyed to your package name
  • .env file and env var support :: Schema fields are also read from environment variables and .env files
  • 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.

Contributions ratios

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

clima-0.13.8.tar.gz (38.0 kB view details)

Uploaded Source

Built Distribution

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

clima-0.13.8-py3-none-any.whl (48.4 kB view details)

Uploaded Python 3

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

Hashes for clima-0.13.8.tar.gz
Algorithm Hash digest
SHA256 5a438d6aa59f70888122bdf131af011c053d22c827fc144cede678686c27de5a
MD5 03adc360177ba2ccfe553c9f88db87cd
BLAKE2b-256 79602fb36b24f2ca05c072bd33b4b1563ad9c0ec00aa3f0d46e96aeb65930e00

See more details on using hashes here.

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

Hashes for clima-0.13.8-py3-none-any.whl
Algorithm Hash digest
SHA256 e176ec076fedf2864ca004c981d32ff8f590b069b910f3a3df56c543af3224d2
MD5 50e4f1014ce36fedece5c76c3dd4a5e6
BLAKE2b-256 dc908df3f1a09a8dcae1a5a4c873e0bfb5b2705a786b3cbf88554dc1b5dbde09

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