Skip to main content

Useful utilities for python and datascience

Project description

Antho Utils

Description

This package is a collection of useful helpers that I regularly use in my projects. It uses a single lightweight dependency: PyYAML. I made a public package because I think it might be helpful to others as well. The following presents a short description of each module.

Color

A zero dependencies api to add color to the terminal. It supports 256 colors and 24-bit colors (True color). It is also possible to theme the colors, so you can use consistent colors in your project. It includes a traceback formatting tool that automatically add colors to the traceback, in order to make it easier and quicker to read. (I use this function in all of my projects)

ConfigFile

A simple api to load and parse configuration files. It supports YAML files. You can verify the configuration format with a template with a single parameter. This can be helpful when you have a long task, such as training a neural network, and you access some keys in the config later. You do not want your long task to crash after few hours or even days because you have the wrong type on a missing key in your config.

It also supports different Profiles, so the same configuration file can be used on different machines or for different , but analogous, tasks. For example, if I want a to run my script locally for quicker developpement, but I train on a HPC server, I do not want to make two configurations files that are almost identical, I can simply create two profiles in the same configuration file with different paths or values, and use the appropriate profile depending on the machine.

Logger

A simple wrapper of the python logging api. It adds colored formatters out of the box, and is easy to configure. It also reduce the number of lines of code needed to log.

from pyutils import logger

logger.debug("My debug message")
logger.info("My info message")
logger.warning("My warning message")
logger.error("My error message")
logger.critical("My critical message")

Progress

This module has a similar function - and usage synthax - to tqdm. However, I believe it is more customizable than tqdm, and more suitable for deep learning progress bar. It also implements out of the box three different types of progress bars: a tqdm-like, a deep-learning one (keras-like) and a pip-like progress bar. It is also possible, and easy to create your own progress bar. Let's look at an example:

# tqdm-like
for i in progress(range(100)):
    time.sleep(0.1)
# keras-like, it will report the loss value in the progress bar in real-time
for bar, batch in progress(dataloader, type="dl").ref():
    time.sleep(0.1)
    bar.repport(loss=...)
# pip-like
for i in progress(range(100), type="pip"):
    time.sleep(0.1)

Installation

It is as easy to install as:

pip install antho-utils

Usage

For a basic usage, you can import everything from the package:

from pyutils import *

or, you can also import the desired tools/modules:

from pyutils.color import Colors, ResetColor, TraceBackColor, ConfigFile, Logger, LoggerType, progress, prange

For a more detailed usage, or to see how you can configure/customize each tool, see the documentation of each module.

Documentation

You can go take a look at the docs folder to see the documentation of each module.

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

antho_utils-0.2.1.tar.gz (21.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

antho_utils-0.2.1-py3-none-any.whl (22.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: antho_utils-0.2.1.tar.gz
  • Upload date:
  • Size: 21.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.22

File hashes

Hashes for antho_utils-0.2.1.tar.gz
Algorithm Hash digest
SHA256 64a40c0ab004b8022ca6b2a1b242ff4bbc3fb8c686e6df7b469397a2bc006a54
MD5 24c251396eaf3ff65b99cdb93ca8e56a
BLAKE2b-256 ea0cb4d6fdea5a07b2e72cf1651bda34b663345cbfd1b6e09231f64fbc2c5319

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for antho_utils-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a72ae97e71acaf391f78a72e1fcd80d46730403db0b640f81c4277f06ddacb1e
MD5 73f3591b538860b6ef6abe610f07475b
BLAKE2b-256 f016f130348660f7fe8cb1707892faa474ab1aed164b7788d6c539be8c5e61eb

See more details on using hashes here.

Supported by

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