Skip to main content

morbin

Base class for creating bindings for command line tools.

Installation

Install with:

pip install morbin

Usage

The easiest way to start is to use the bundled template generator.
The only argument it requires is the name of the program you want to create bindings for.

As an example we'll do Pip.

Running morbin pip in your terminal will produce a file named pip.py in your current directory.
It should look like this:

from morbin import Morbin, Output


class Pip(Morbin):
    @property
    def program(self) -> str:
    return "pip"

Additional functions should be built on top of the run function and return its output.

After adding functions for install and upgrade the class should look like this:

from morbin import Morbin, Output


class Pip(Morbin):
    @property
    def program(self) -> str:
    return "pip"
    
    def install(self, package:str, *args:str)->Output:
        return self.run("install", package, *args)
    
    def upgrade(self, package:str)->Output:
        return self.install(package, "--upgrade")
    
    def install_requirements(self)->Output:
        return self.install("-r", "requirements.txt")

It can be used like:

pip = Pip()
output = pip.install_requirements()

The Output object each function returns is a dataclass with three fields: return_code, stdout, and stderr.

@dataclass
class Output:
    """Dataclass representing the output of a terminal command.

    #### Fields:
    * `return_code: list[int]`
    * `stdout: str`
    * `stderr: str`"""

    return_code: list[int]
    stdout: str = ""
    stderr: str = ""

    def __add__(self, output: Self) -> Self:
        return Output(
            self.return_code + output.return_code,
            self.stdout + output.stdout,
            self.stderr + output.stderr,
        )

By default stdout and stderr are not captured.
They are sent to wherever they normally would be and the stdout and stderr fields of the Output object will be empty strings.
stdout and stderr can be captured by either setting the capture_output property of a class instance to True or by using the capturing_output context manager.
To get the output of install_requirements:

pip = Pip(capture_output=True)
text = pip.install_requirements().stdout

or

pip = Pip()
with pip.capturing_output():
    text = pip.install_requirements().stdout

Metadata

Release files for morbin 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for morbin 1.0.1
File Size Uploaded Provenance Actions
morbin-1.0.1.tar.gz 4.4 kB Without provenance Details for morbin-1.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for morbin 1.0.1
File Interpreter ABI Platform Actions
morbin-1.0.1-py3-none-any.whl Python 3 none any Details for morbin-1.0.1-py3-none-any.whl

Total release size: 9.9 kB

Release files / morbin-1.0.1.tar.gz

Download URL morbin-1.0.1.tar.gz
Size 4.4 kB
Tags Source
SHA-256 checksum
How to use checksums
e84ff43fe8c3c883ac25d6dc1471f3f22a58222e539313645d965cd5fde86b3e
BLAKE2b-256 checksum
How to use checksums
59d15e2fd489e3f82c6dfc38b64c99d37e6095386dcc923f1234692c097a2b90
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.0

Release files / morbin-1.0.1-py3-none-any.whl

Download URL morbin-1.0.1-py3-none-any.whl
Size 5.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0c3a0b1482fb932ffd5e1fa43071bc9d6d27e8ce20060c5b26c8989158eddbe1
BLAKE2b-256 checksum
How to use checksums
8465fc4fab68dcbdfbbbb4bcd1a93744d48e0def4ef9e1b8ddb9dd7954191343
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.0

Security for morbin 1.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page