Skip to main content

an opinionated set of utilities designed to be easily included in any number of projects

Project description

About

This package contains a set of utilities useful for building python libraries, scripts, and command-line utilities

It's designed to be easy to include in other projects. all of its mainline dependencies are vendored and all modules which have external un-vendorable dependencies are available as optional extras

Install

pip install si-utils

To make use of optional extras, like the yaml module or the log module:

pip install si-utils[yaml] # or si-utils[log], or si-utils[yaml,log]

Usage

This toolkit makes it really easy to write small, simple, well designed CLI utilities In fact, the aim of this project is to make well-engineered CLIs almost as easy to write and deploy as basic python scripts it leverages a lot of really fantastic modern libraries and tools to do so, like poetry, typer, and loguru

let's assume you've created a new project with poetry new, and you want to add a CLI interface to it. here's one way to do that: create a __main__.py file in your package like so:

import os

from .common import my_super_awesome_function

from si_utils.main import ...
from si_utils.log import configure_logging
import typer
from loguru import logger

app = typer.Typer()


@app.callback()
def callback(verbose: bool = False):
    """
    Here is my app's main help string
    """
    log_level = 'DEBUG' if verbose else 'INFO'
    configure_logging(
        'my_app_name', 
        stderr_level=log_level, 
        logfile_level='DEBUG', 
        sentry_level=None)


@app.command()
def my_command(option: bool):
    logger.debug("running my-command")  # this will only get printed if the --verbose flag is set
    my_super_awesome_function(option)


if __name__ == "__main__":
    if os.environ.get('PYDEBUG'):
        # we're in a debugger session
        #here we can put whatever debugging code we want
        # we can configure logging so all messages up to DEBUG are logged to stderr, and nothing gets logged to file:
        configure_logging('my_app_name', 'DEBUG', None, None)
        # do debugging stuff here
        logger.debug("I'm a debug message!")
        exit()
    try:
        app()  # cli code goes here
    except KeyboardInterrupt:
        print("Aborted!")
        exit()

the main api (all the stuff directly importable from si_utils) consists of:

  • every function defined in the main module
  • the configure_logging function from the log module

apart from that, there are other modules which can be imported separately:

yaml has a whole bunch of useful and sometimes esoteric utilities for working with yaml files, built on top of ruamel.yaml

dev_utils has commmand-line utilities for working with python projects, specifically made for projects that use poetry

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

si_utils-0.2.1.tar.gz (186.3 kB view details)

Uploaded Source

Built Distribution

si_utils-0.2.1-py3-none-any.whl (204.6 kB view details)

Uploaded Python 3

File details

Details for the file si_utils-0.2.1.tar.gz.

File metadata

  • Download URL: si_utils-0.2.1.tar.gz
  • Upload date:
  • Size: 186.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.6.8 Linux/3.10.0-1062.18.1.el7.x86_64

File hashes

Hashes for si_utils-0.2.1.tar.gz
Algorithm Hash digest
SHA256 cdcfdc7be3dd306b2e5a5136e29f2f47ba2a3a5782e1ee62116e569116ad17da
MD5 d5ce9fa998ad6a3af9670727dc85571d
BLAKE2b-256 51994492b841d000e0afbddf917b47cdeadc963e47d17753ccbfa6c07407e79f

See more details on using hashes here.

File details

Details for the file si_utils-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: si_utils-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 204.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.6.8 Linux/3.10.0-1062.18.1.el7.x86_64

File hashes

Hashes for si_utils-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6f0d2735ec34ec3c03d336d13797f0c0873ba4cb28ed1c747fadbd5c5a0bc4d8
MD5 80f044fb84d62b5d7ce72e83c213c208
BLAKE2b-256 919c4e657552119179f9e39cc41ff326dae271e36ecbd8d2b6fa48f9eded689c

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