Skip to main content

A cli tool that makes any Python function an executable

Project description

Bistrot

A chef drawing

A cli tool that transforms any Python function into an executable, or can easily print any constant in a codebase or library

Hatch project linting - Ruff code style - Black types - Mypy License

It takes an existing Python function in a project and allows you to call it as an independent executable. All the function arguments become cli arguments with argparse.

Examples

Let's consider this example from examples/ops.py:

#examples/ops.py
def add(a: int, b: int) -> int:
    return a + b

We can call this function from the command line using bistrot:

$ bistrot examples.ops:add --x=2 --y=3
bistrot> 5

Or it can use positional arguments if they are defined as such in the function:

$ bistrot examples.ops:add 2 3
bistrot> 5

However, the mandatory arguments must all be either positional or named in a cli call.

It also works with static and class methods

#examples/klass.py
import bistrot

class UsefulClass:
    @staticmethod
    def version():
        return bistrot.__version__
$ bistrot examples.klass:UsefulClass.version
bistrot> 0.1.0a1

The same result can be achieved by targeting directly the __version__ variable:

$ bistrot bistrot:__version__
bistrot> 0.1.0a1

It is also possible to call methods on strings

$ bistrot '{\"hello\"}:upper'
bistrot> HELLO

Install

Bistrot is on pypi and it has no dependencies! Install it simply with

$ pip install bistrot

Or you may want to install it with pipx for global usage

$ pipx install bistrot
$ bistrot <cmds>

And verify your installation with

$ bistrot --version
bistrot> 0.1.0a1

Warning

This project is still experimental and is guaranteed to work only with primitive Python types.

Links


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

bistrot-0.1.0a4.tar.gz (11.2 kB view details)

Uploaded Source

Built Distribution

bistrot-0.1.0a4-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file bistrot-0.1.0a4.tar.gz.

File metadata

  • Download URL: bistrot-0.1.0a4.tar.gz
  • Upload date:
  • Size: 11.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.23.3

File hashes

Hashes for bistrot-0.1.0a4.tar.gz
Algorithm Hash digest
SHA256 b1f0ba685d38242386877f309c8f5366ab1c1f05fb8df0c7566e80f9782a87e5
MD5 7a1143f004bb73147cfe78b22f002807
BLAKE2b-256 b442f113c1b9fe3badfaaac0965c2de679ae8bac426c49fd4ccac1c86ba20ba4

See more details on using hashes here.

File details

Details for the file bistrot-0.1.0a4-py3-none-any.whl.

File metadata

  • Download URL: bistrot-0.1.0a4-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.23.3

File hashes

Hashes for bistrot-0.1.0a4-py3-none-any.whl
Algorithm Hash digest
SHA256 4827d0fb029ded49f7a77c460609e43c677f3b7cd652bca0187e3deec95924fb
MD5 4621aee9d5085964a5cf366b80c286dc
BLAKE2b-256 454b37e1698ca96ef0ac3f3bb098500d4e1efc4d01655249aad856656adf553c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page