Skip to main content

red-utils

⚠️Important⚠️: This is my first Python package. I'm experimenting with CI/CD and Pypi. This library is most likely not useful to anyone else, may be broken at times, may undergo refactors with little to no notice/documentation, and all that other awful stuff that comes with being an amateur developer doing this in their free time 🙃

Table of Contents

Description

A collection of utility scripts/functions that I use frequently. Includes helper functions/default variables for libraries like loguru, diskcache, and msgpack.

The utilities are broken down into 2 modules:

  • std: Utilities with no external dependencies, only the Python stdlib.
  • ext: Utilities for dependencies like loguru and msgpack
    • Note: It is generally a good practice to import ext modules as a whole, instead of importing functions/variables from the module.

    • This is because some of the function names I chose may be common (like get_ts() in the ext.time_utils module).

    • Example:

      from red_utils.ext import time_utils
      
      now = time_utils.get_ts()
      

      or, with pendulum:

      from red_utils.ext.time_utils import pendulum_utils
      
      now = pendulum_utils.get_ts()
      

Common code shared by the std and ext modules can be imported from red_utils.core and red_utils.domain. Any code in these modules should be clean of any external dependency. This is because the std module imports from core, and adding non-stdlib functionality in red_utils.core breaks the philosophy of the stdlib module. I may introduce a red_utils.ext.core at some point.

Some domain objects (dataclass or regular Python classes) may be stored in red_utils.domain. As of release v0.2.12, this module is empty, but future releases may bring some utilities in the form of a class.

Custom/common exceptions are stored in red_utils.exc.

Dynamic imports

The red-utils package makes use of the Python stdlib pkgutil module to control imports. Packages in the ext module are only imported and available in red_utils if the corresponding dependency exists.

For instance, red_utils.ext.msgpack_utils will only be available if this check in src/red_utils/ext passes:

import pkgutil

...

if pkgutil.find_loader("msgpack"):
  from . import msgpack_utils

pkgutil.find_loader() is used throughout the app to control imports and ensure red_utils is stable, by keeping uninstalled module's utilities out of the namespace.

Installation

This project uses dependencies groups, meaning it can be installed with pip install red-utils for the base package, or with dependency groups like pip install red-utils[all] (to install all packages with a corresponding red-util module), pip install red-utils[http] (to install some helpful packages for HTTP requests, i.e. httpx and diskcache), and more.

  • pip
    • pip install red-utils
  • pdm
    • pdm add red-utils

Dependency groups:

Note: I will do my best to update this, but to get an accurate view of available dependency groups and the packages that will be installed, check the pyproject.toml file. Look for the dependency lists, i.e. dependencies = [ (the base set of dependencies), all = [, http = [, etc.

[all]: Install all packages that have a corresponding util. This may be a large install, and is generally not recommended.

[arrow]: By default, the pendulum library is used for time_utils. Installing red_utils[arrow] allows for importing arrow functions from red_utils.ext.time_utils.arrow.

[fastapi]: Dependencies for fastapi_utils

[http]: My standard "HTTP toolkit." Comes with a request client (httpx), logging (loguru), caching (diskcache), & more.

Dependency install group examples

  • pip:
    • pip install red-utils[fastapi,http]
  • pdm:
    • pdm add red-utils[fastapi,http]

Modules

Check the Github page to see modules in the ext and std modules (or click one of those words to be taken there).

Developing red-utils

Please see the developing docs for instructions on setting up a dev environment to work on red-utils.

Metadata

Release files for red_utils 0.2.25

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

Source distribution (sdist)

Source distribution for red_utils 0.2.25
File Size Uploaded Provenance Actions
red_utils-0.2.25.tar.gz 86.3 kB Without provenance Details for red_utils-0.2.25.tar.gz

Built distribution (wheel)

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

Total release size: 218.8 kB

Release files / red_utils-0.2.25.tar.gz

Download URL red_utils-0.2.25.tar.gz
Size 86.3 kB
Tags Source
SHA-256 checksum
How to use checksums
a499102a9745bb0e12d5166bcb02465c369fd0143e67955dbfd25769cd6a9cbe
BLAKE2b-256 checksum
How to use checksums
20e274c8dbdee5a9c9af9615a4778eacf5959d57b9f0ad1a0ba35c78a5047a86
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via pdm/2.15.4 CPython/3.11.6 Linux/5.15.0-112-generic

Release files / red_utils-0.2.25-py3-none-any.whl

Download URL red_utils-0.2.25-py3-none-any.whl
Size 132.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d1fe9860aebccd63c31923015c43a6b1d43a9abbcc74fe7070665d0936815d5c
BLAKE2b-256 checksum
How to use checksums
215821e6867e3ab3acaee770a567865bb15c5192d15f83990c8e166f863ca9df
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via pdm/2.15.4 CPython/3.11.6 Linux/5.15.0-112-generic

Security for red_utils 0.2.25

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.

Release history Release notifications | RSS feed

This release

0.2.25 This release

2 release files No provenance

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