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.1.7.tar.gz (24.2 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.1.7-py3-none-any.whl (19.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: magicli-2.1.7.tar.gz
  • Upload date:
  • Size: 24.2 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.1.7.tar.gz
Algorithm Hash digest
SHA256 9fe9ceb894c0157503b24672c373fa61b7e7317c34961f27646d006b292e78cc
MD5 3580af076ae0a2cdc415badc4b92e1a4
BLAKE2b-256 41da7a2eb622e7b97d60fb08eda174a7cb6b5c59fc43cf1e81ac2271761fa13f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: magicli-2.1.7-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.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 cde4d981685badebe2a485a3d4115b9f79fb60930e1acbb57d7f5a9b98dd16c2
MD5 d8d3be91d61233265f5fb16e57503767
BLAKE2b-256 5922ebff6701856ee5be1bdde3a1240f3dd566f48427046a9967bc9941438426

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