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 uoft_core
to include all optional dependencies, run
pip install uoft_core[all]
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 common.py files with your super handy dandy useful function in it:
from loguru import logger
def my_super_awesome_function():
logger.debug("I'm running my_package.common.my_super_awesome_function!")
create a __main__.py file in your package like so:
import os
from .common import my_super_awesome_function
from at.utils 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
Users will see this when they run `python -m my_package`
"""
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):
"""
Here's the help text my users will see when they run `python -m my_package my-command -h`
"""
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 at_utils) consists of:
- every function defined in the
mainmodule - the
configure_loggingfunction from thelogmodule
configure_logging has an option to enable logging to sentry. in order to use it, you need to install at_utils with the sentry extra (ie pip install at-utils[sentry] or poetry add -D at-utils[sentry])
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
Metadata
Release files for uoft-core 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| uoft_core-1.0.1.tar.gz | 3.6 MB | Without provenance | Details for uoft_core-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| uoft_core-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for uoft_core-1.0.1-py3-none-any.whl |
Total release size: 4.0 MB
Release files / uoft_core-1.0.1.tar.gz
| Download URL | uoft_core-1.0.1.tar.gz |
|---|---|
| Size | 3.6 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3764dce5599e4d43ac3316ae0275b14a844b31b8feb6d3c5a7cf4020ff8b4e31
|
|
BLAKE2b-256 checksum How to use checksums |
a7a6383ee7e812e3b95c81bf83f3749ff4eec92dc1ca532bb6f05f00d26df629
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.10.4
|
Release files / uoft_core-1.0.1-py3-none-any.whl
| Download URL | uoft_core-1.0.1-py3-none-any.whl |
|---|---|
| Size | 491.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
41f9e3ff0ec5d035fe091fd11af369c70ee429d1928968418923965cc845a1d7
|
|
BLAKE2b-256 checksum How to use checksums |
cc45fc0cad5cb47a9321330076ff8808dc262ebb572d1bc025a20ae7a4508b33
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.10.4
|
Security for uoft-core 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.