Skip to main content

Automatically generates a CLI from functions.

Project description

magiᴄʟɪ✨

magicli

automatically turns a file into a CLI by introspecting its functions.

  • no boilerplate
  • automatic help message
  • type casting included
  • supports sub-commands
  • complete pyproject.toml setup
  • ready for upload to pypi

Create a full CLI in only 2 lines of code:

# hello.py
def hello(name, greeting="hello"):
    print(greeting, name)

calling magicli creates this CLI:

hello world example

(animated terminal created with clivio)

Quick start

Install magicli

pip install magicli

Setup your repository

Initialize repo

git init

Add version info (optional)

git tag 1.0.0

Automatically create CLI

magicli

Make sure the name of your CLI, the module name and the name of the function have to same name.

Install your Python package

pip install .

or after uploading to pypi:

pip install <package_name>

Advanced use

Using subcommands

# hello.py
def hello(): ...

def world(times=1):
    for _ in range(times):
        print("hello world")
$ hello world --times 2
hello world
hello world

Help message

By default, the docstring of the function will be displayed.

If no docstring is specified, an error message will be printed.

Development

Run pytest with coverage report:

python3 -m pytest -s --cov=magicli --cov-report=term-missing

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

magicli-2.2.0.tar.gz (23.0 kB view details)

Uploaded Source

Built Distribution

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

magicli-2.2.0-py3-none-any.whl (19.9 kB view details)

Uploaded Python 3

File details

Details for the file magicli-2.2.0.tar.gz.

File metadata

  • Download URL: magicli-2.2.0.tar.gz
  • Upload date:
  • Size: 23.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.24 {"installer":{"name":"uv","version":"0.11.24","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 magicli-2.2.0.tar.gz
Algorithm Hash digest
SHA256 d32ba679f5dd0b8fd69c4e5040df04b239214f24bf95048a6223f959d3a98ce3
MD5 7d4c08fddd95cc499133e84904fd9628
BLAKE2b-256 5f2e3a3aa47aaa7f8334800644395b8ac403535dd498b399e87663abeef5afb2

See more details on using hashes here.

File details

Details for the file magicli-2.2.0-py3-none-any.whl.

File metadata

  • Download URL: magicli-2.2.0-py3-none-any.whl
  • Upload date:
  • Size: 19.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.24 {"installer":{"name":"uv","version":"0.11.24","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 magicli-2.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5430b5017046ccc57cf4016f2aaf509e4007b36d2b7d9f679d2e2e4fdc387b56
MD5 fb703752471e30f838a393e33e12904c
BLAKE2b-256 9aa46925d0ff4b0dc8769d933b464da72bd46c54987e83ad7b45a03864a7b3f2

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