Skip to main content

Automatically generates a CLI from functions.

Project description

magiᴄʟɪ✨

Automatically generates a CLI from functions of a module.

Install

pip install magicli

Get started

Simple usage example.

# module.py
def hello(name, times=1):
    for _ in range(times):
        print("hello", name)

Then run this in your terminal to initialize the CLI:

magicli

You are now able to install your package:

pip install .

And then call it:

$ hello world --times 2
hello world
hello world

Define name of CLI in pyproject.toml

The terminal command magicli adds the following to your pyproject.toml.

[project.scripts]
hello = "magicli:magicli"

Important: Make sure the name of your CLI, the module name and the name of the function to be called are the same!

.
├── hello.py
└── pyproject.toml

You can now pip install your code and call it like this:

$ hello world --times 2
hello world
hello world

Using subcommands

# module.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.2.tar.gz (21.8 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.2-py3-none-any.whl (18.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: magicli-2.1.2.tar.gz
  • Upload date:
  • Size: 21.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.17 {"installer":{"name":"uv","version":"0.11.17","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.2.tar.gz
Algorithm Hash digest
SHA256 134517f4de0c8af5045c8b76fd4e0461a97a6f923567039f7a3daf3e984bfcc4
MD5 60bc073f0f81a99617cdd1560ab0f7cc
BLAKE2b-256 efc1426ac84b6005c000c472c146f7a6943fb1ab762c744b7febf7fdab5aeee8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: magicli-2.1.2-py3-none-any.whl
  • Upload date:
  • Size: 18.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.17 {"installer":{"name":"uv","version":"0.11.17","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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6dc81e274e207f4a46e1a5c06c586375a5deead9f8984fc41f4ca87510a7eec8
MD5 793645c99006e77fd320bb9572c25edb
BLAKE2b-256 b0eb6fdea0fbf2b48bf3012d4893bde3fcc7d80abd7c2fe02e2d15bd75fb205c

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