Skip to main content

No project description provided

Project description

Welcome to Invokify

Invokify is a lightweight library that allows you to run functions from a string or list of values.


Installing

Invokify is published on PyPI so you can easily install it with either pip or poetry.

pip install invokify
poetry add invokify

This package is for python 3.10+


Getting started

Let's create a simple command-line command.

We can start by importing the InvokeEngine from invokify:

from invokify import InvokeEngine

Now we need to create an engine to hold our commands:

engine = InvokeEngine()

Once we have our engine set up, all we need to do is decorate our target function using the engine's command method:

@engine.command
def greet(user: str):
    print(f"Hello {user}!")

Congrats, that's all you need to do to create a command! Our next goal will be to parse our command by feeding our engine's parse method a list of values.

cmd, args, callstack = engine.parse(["greet", "Jeff"])

The parse method will return a tuple containing three values:

  1. The command if one was found. If no command was found, it will return None
  2. Any remaining arguments that were passed. The parse method will recursively look for subcommands until it cannot find any, and the remaining arguments will be passed back.
  3. The callstack. A list of the commands and subcommands that were passed in.

Once you have your command, you can execute it easily just by calling it. If your command accept arguments, you can pass args to it.

cmd(*args)

Output:

Hello Jeff!

To actually run commands on the command line, we can just set up a simple input loop. Invokify has a simple built-in parser called string_to_args() that can turn a string into a list of arguments, keeping things like strings and lists intact, and converting numbers automatically.

while True:
    user = input()

    cleaned = string_to_args(user)

    cmd, args, cs = engine.parse(cleaned)

    if cmd:
        cmd(*args)
    else:
        print("No command was found.")

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

invokify-0.1.4.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

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

invokify-0.1.4-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file invokify-0.1.4.tar.gz.

File metadata

  • Download URL: invokify-0.1.4.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.12.2 Windows/11

File hashes

Hashes for invokify-0.1.4.tar.gz
Algorithm Hash digest
SHA256 8495bd40294d1b21dbf80a321a6ad01beaa2157de25498e91e6fd2cd0162be9e
MD5 fb5e2f20cc1a47cf2fdd6365ebbb5643
BLAKE2b-256 3537475a9cbbf2d0d4646280e2ca30d8583df6c8454c43d4a40448c948e9f2da

See more details on using hashes here.

File details

Details for the file invokify-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: invokify-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.12.2 Windows/11

File hashes

Hashes for invokify-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 a426bcca8ff09397b6fabc35d28bab901e3e5bcc13c737f6f8b961c61f5100a7
MD5 a0b2a2026014b50313809f80a8f962ed
BLAKE2b-256 106a273ce86afa345e6fb2fcaa5f8badc576cd874574f27137ca4347a852c1b1

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