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

Uploaded Python 3

File details

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

File metadata

  • Download URL: magicli-2.1.6.tar.gz
  • Upload date:
  • Size: 24.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","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.6.tar.gz
Algorithm Hash digest
SHA256 30b54056490d629b1c2a8addb62237a12f1e74fa27aa8cf4213f9a79dee84b38
MD5 7d5c6aedd08c45234dea3faf834d9b16
BLAKE2b-256 b1d63e0d1afc5d53d309dc20bc2cee4e4926c7b1c8d11fa7183d9a0dc5216a37

See more details on using hashes here.

File details

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

File metadata

  • Download URL: magicli-2.1.6-py3-none-any.whl
  • Upload date:
  • Size: 19.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","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.6-py3-none-any.whl
Algorithm Hash digest
SHA256 7ebaf3a86bca6666ef9d046b8f052238cda87eb22fac860ffcef5b316a39e7d2
MD5 43191cdcffd4e21383e31dac59d3ca4f
BLAKE2b-256 dbfcc80e38273a9bdf45691461dc325e7128ab8f4b511f18424d26913e714884

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