Набор простых и удобных утилит для Python, который избавляет от рутины при работе с конфигурацией и логированием в новых проектах.
Project description
chutils: Stop the Routine!
chutils is a set of simple utilities for Python designed to eliminate the repetitive setup of configuration, logging, and secrets in your projects.
Start a new project and focus on what matters, not the routine.
Full documentation is available on our website (currently in Russian).
The Problem
Every time you start a new project, you have to solve the same tasks:
- How to conveniently read settings from a configuration file?
- How to configure logging to write messages to both the console and a file with daily rotation?
- How to securely store API keys without hardcoding them in the code?
- How to make it all work "out of the box" without manually defining paths?
chutils offers ready-made solutions for all these problems.
Key Features
- ✨ Zero Configuration: The library automatically finds your project root and the
config.ymlorconfig.inifile. It uses lazy initialization — no heavy operations until you actually need them. - ⚙️ Flexible Configuration: Support for
YAMLandINIformats. Simple functions for retrieving typed data. - ✍️ Advanced Logger: The
setup_logger()function configures logging to the console and rotating files out of the box. It returns a custom logger with additional debug levels (devdebug,mediumdebug). - 🔒 Secure Secret Storage: The
secret_managermodule provides a simple interface for saving and retrieving secrets via the systemkeyring, with a fallback to.envfiles. - ⚡ Async Ready: Most core functions have asynchronous versions (prefixed with
a) for non-blocking execution. - 🚀 Ready to Use: Just install and use.
Installation
poetry add chutils
Or using pip:
pip install chutils
Examples
In the /examples folder, you will find ready-to-run scripts demonstrating the library's key features.
Each example focuses on a specific task.
Quick Start
1. Working with Configuration
-
(Optional) Create a
config.ymlfile in your project root:# config.yml Database: host: localhost port: 5432
-
Get values in your code:
from chutils import get_config_value, get_config_int db_host = get_config_value("Database", "host", fallback="127.0.0.1") db_port = get_config_int("Database", "port", fallback=5432)
Overriding Configuration with Local Files (
config.local.yml)You can create a
config.local.ymlnext to your main file. Values from the local file will override corresponding values from the main file. This is perfect for local development or storing sensitive data (ensure*.local.*is in your.gitignore).
2. Logging Setup
-
Configure and use the logger:
from chutils import setup_logger, ChutilsLogger # Automatically reads settings from [Logging] section in config.yml logger: ChutilsLogger = setup_logger() logger.info("Application started.") logger.devdebug("Deep debug message (level 9).")
Controlling Logging via Environment Variables
CH_LOG_NO_TIME=true: Removes the date/time from the log format (for clean Docker logs).CH_LOG_NO_FILE=true: Disables creating log files.
These variables have highest priority and override any code or config settings.
3. Secret Management
SecretManager looks for secrets in the following order: Keyring > .env File > Environment Variables.
from chutils import SecretManager
secrets = SecretManager("my_awesome_app")
# Save once
secrets.save_secret("API_KEY", "secret-value-123")
# Use everywhere
key = secrets.get_secret("API_KEY")
Disabling Keyring (Optional)
In environments like Docker or CI/CD where keyring is unavailable, you can suppress warnings and skip the check:
- Set
CH_DISABLE_KEYRING_WARNING=truein environment. - Or add
disable_keyring: trueundersecretssection inconfig.yml.
API Overview
Configuration (chutils.config)
get_config_value(section, key, fallback)/aget_config()get_config_int,get_config_boolean,get_config_list,get_config_pathsave_config_value(section, key, value)/asave_config_value()
Logging (chutils.logger)
setup_logger(name, log_level, log_file_name, rotation_type, compress, ...)- Levels:
logger.devdebug(9),logger.mediumdebug(15), and all standard ones.
Secret Management (chutils.secret_manager)
SecretManager(service_name, prefix)save_secret/asave_secretget_secret/aget_secretdelete_secret/adelete_secret
Decorators (chutils.decorators)
@log_function_details: Logs arguments, execution time, and result (usesDEVDEBUGlevel).
License
The project is distributed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file chutils-2.5.0.tar.gz.
File metadata
- Download URL: chutils-2.5.0.tar.gz
- Upload date:
- Size: 24.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.2 CPython/3.13.5 Windows/11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
07732bba68292772b710e2ad5470818b29c4787c7da9386da8796e49ce9cf871
|
|
| MD5 |
a8730a0c104d6380fce5a786855be294
|
|
| BLAKE2b-256 |
643a7b33e07bcf062eadc6732180b567c9521812c85c47692c5a106b2b76f69f
|
File details
Details for the file chutils-2.5.0-py3-none-any.whl.
File metadata
- Download URL: chutils-2.5.0-py3-none-any.whl
- Upload date:
- Size: 25.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.2 CPython/3.13.5 Windows/11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
986b0541b84fa1a98df7f9f7e6971831e240673a0c19c4f077a3d1e4c502dbce
|
|
| MD5 |
ee893c18364617336a92e390bfd812e1
|
|
| BLAKE2b-256 |
2cbc40ecc931065433db8493697e83a667909b09fd8402d60a503d2a51be4e8d
|