Skip to main content

Automatically generates a CLI from functions.

Project description

magiᴄʟɪ✨

Automatically generates a CLI from functions.

Install

pip install magicli

Get started

Simple usage example.

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

import magicli

Make sure you import magicli at the end of the file.

$ python3 module.py world --times 2
hello world
hello world

Define name of CLI in pyproject.toml

Add the following to your pyproject.toml.

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

This example assumes the following project structure with the CLI to be created specified in the file module.py.

.
├── module.py
└── pyproject.toml

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

$ hello world --times 2
hello world
hello world

Make sure to adjust the path to module if your project layout is different.

Using subcommands

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

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

import magicli
$ 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, there will be no output.

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-1.1.0.tar.gz (2.7 kB view details)

Uploaded Source

Built Distribution

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

magicli-1.1.0-py2.py3-none-any.whl (3.1 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

  • Download URL: magicli-1.1.0.tar.gz
  • Upload date:
  • Size: 2.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.6.14

File hashes

Hashes for magicli-1.1.0.tar.gz
Algorithm Hash digest
SHA256 2009e03aef1cdbd6c3c094ae9a6dec325dc0e3c8ef4019dc43fc9f6e2c87cafe
MD5 f5c9e61f255fba347fe7ba67e9f9a851
BLAKE2b-256 1b2af1977920af4869b9cddc31a75fec231f419f225840913bb0941edb36ef58

See more details on using hashes here.

File details

Details for the file magicli-1.1.0-py2.py3-none-any.whl.

File metadata

  • Download URL: magicli-1.1.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 3.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.6.14

File hashes

Hashes for magicli-1.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 5c6abfca56c5eb540173ba4262e71cc755b55d40825835711cd8537ee74a1791
MD5 858b53860960243793eba5488d2df11a
BLAKE2b-256 06036ddb12d4c58f6ad8647d84fe6ff23512c450f3d923e668a05ec3be4b9df4

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