chutils 2.4.0__tar.gz → 2.5.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2025 Chu4hel
3
+ Copyright (c) 2025-2026 Chu4hel
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
chutils-2.5.0/PKG-INFO ADDED
@@ -0,0 +1,178 @@
1
+ Metadata-Version: 2.4
2
+ Name: chutils
3
+ Version: 2.5.0
4
+ Summary: Набор простых и удобных утилит для Python, который избавляет от рутины при работе с конфигурацией и логированием в новых проектах.
5
+ License: MIT
6
+ License-File: LICENSE
7
+ Author: Chu4hel
8
+ Author-email: sergeiivanov636@gmail.com
9
+ Requires-Python: >=3.9, !=2.7.*, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*, !=3.6.*, !=3.7.*, !=3.8.*
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Programming Language :: Python :: 3.13
16
+ Classifier: Programming Language :: Python :: 3.14
17
+ Requires-Dist: keyring (>=25.7.0,<26.0.0)
18
+ Requires-Dist: python-dotenv (==1.2.1) ; python_version < "3.10"
19
+ Requires-Dist: python-dotenv (>=1.2.2,<2.0.0) ; python_version >= "3.10"
20
+ Requires-Dist: pyyaml (>=6.0.3,<7.0.0)
21
+ Description-Content-Type: text/markdown
22
+
23
+ [Русская версия](docs/README_RU.md)
24
+
25
+ # chutils: Stop the Routine!
26
+
27
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
28
+ [![Python](https://img.shields.io/badge/python-3.9%2B-blue.svg)](https://www.python.org/downloads/)
29
+ [![PyPI version](https://badge.fury.io/py/chutils.svg)](https://badge.fury.io/py/chutils)
30
+ [![Documentation](https://img.shields.io/badge/documentation-read-brightgreen)](https://Chu4hel.github.io/chutils/)
31
+
32
+ **chutils** is a set of simple utilities for Python designed to eliminate the repetitive setup of configuration,
33
+ logging, and secrets in your projects.
34
+
35
+ Start a new project and focus on what matters, not the routine.
36
+
37
+ Full documentation is available on [our website](https://Chu4hel.github.io/chutils/) (currently in Russian).
38
+
39
+ ## The Problem
40
+
41
+ Every time you start a new project, you have to solve the same tasks:
42
+
43
+ - How to conveniently read settings from a configuration file?
44
+ - How to configure logging to write messages to both the console and a file with daily rotation?
45
+ - How to securely store API keys without hardcoding them in the code?
46
+ - How to make it all work "out of the box" without manually defining paths?
47
+
48
+ **chutils** offers ready-made solutions for all these problems.
49
+
50
+ ## Key Features
51
+
52
+ - **✨ Zero Configuration:** The library **automatically** finds your project root and the `config.yml` or `config.ini`
53
+ file. It uses **lazy initialization** — no heavy operations until you actually need them.
54
+ - **⚙️ Flexible Configuration:** Support for `YAML` and `INI` formats. Simple functions for retrieving typed data.
55
+ - **✍️ Advanced Logger:** The `setup_logger()` function configures logging to the console and rotating files out of the
56
+ box. It returns a custom logger with additional debug levels (`devdebug`, `mediumdebug`).
57
+ - **🔒 Secure Secret Storage:** The `secret_manager` module provides a simple interface for saving and retrieving secrets
58
+ via the system `keyring`, with a fallback to `.env` files.
59
+ - **⚡ Async Ready:** Most core functions have asynchronous versions (prefixed with `a`) for non-blocking execution.
60
+ - **🚀 Ready to Use:** Just install and use.
61
+
62
+ ## Installation
63
+
64
+ ```bash
65
+ poetry add chutils
66
+ ```
67
+
68
+ Or using pip:
69
+
70
+ ```bash
71
+ pip install chutils
72
+ ```
73
+
74
+ ## Examples
75
+
76
+ In the [`/examples`](./examples/) folder, you will find ready-to-run scripts demonstrating the library's key features.
77
+ Each example focuses on a specific task.
78
+
79
+ ## Quick Start
80
+
81
+ ### 1. Working with Configuration
82
+
83
+ 1. (Optional) Create a `config.yml` file in your project root:
84
+
85
+ ```yaml
86
+ # config.yml
87
+ Database:
88
+ host: localhost
89
+ port: 5432
90
+ ```
91
+
92
+ 2. Get values in your code:
93
+
94
+ ```python
95
+ from chutils import get_config_value, get_config_int
96
+
97
+ db_host = get_config_value("Database", "host", fallback="127.0.0.1")
98
+ db_port = get_config_int("Database", "port", fallback=5432)
99
+ ```
100
+
101
+ #### Overriding Configuration with Local Files (`config.local.yml`)
102
+
103
+ You can create a `config.local.yml` next to your main file. Values from the local file will **override**
104
+ corresponding values from the main file. This is perfect for local development or storing sensitive data (ensure
105
+ `*.local.*` is in your `.gitignore`).
106
+
107
+ ### 2. Logging Setup
108
+
109
+ 1. Configure and use the logger:
110
+
111
+ ```python
112
+ from chutils import setup_logger, ChutilsLogger
113
+
114
+ # Automatically reads settings from [Logging] section in config.yml
115
+ logger: ChutilsLogger = setup_logger()
116
+
117
+ logger.info("Application started.")
118
+ logger.devdebug("Deep debug message (level 9).")
119
+ ```
120
+
121
+ #### Controlling Logging via Environment Variables
122
+
123
+ - `CH_LOG_NO_TIME=true`: Removes the date/time from the log format (for clean Docker logs).
124
+ - `CH_LOG_NO_FILE=true`: Disables creating log files.
125
+
126
+ These variables have **highest priority** and override any code or config settings.
127
+
128
+ ### 3. Secret Management
129
+
130
+ `SecretManager` looks for secrets in the following order: **Keyring > .env File > Environment Variables**.
131
+
132
+ ```python
133
+ from chutils import SecretManager
134
+
135
+ secrets = SecretManager("my_awesome_app")
136
+
137
+ # Save once
138
+ secrets.save_secret("API_KEY", "secret-value-123")
139
+
140
+ # Use everywhere
141
+ key = secrets.get_secret("API_KEY")
142
+ ```
143
+
144
+ #### Disabling Keyring (Optional)
145
+
146
+ In environments like Docker or CI/CD where `keyring` is unavailable, you can suppress warnings and skip the check:
147
+
148
+ - Set `CH_DISABLE_KEYRING_WARNING=true` in environment.
149
+ - Or add `disable_keyring: true` under `secrets` section in `config.yml`.
150
+
151
+ ## API Overview
152
+
153
+ ### Configuration (`chutils.config`)
154
+
155
+ - `get_config_value(section, key, fallback)` / `aget_config()`
156
+ - `get_config_int`, `get_config_boolean`, `get_config_list`, `get_config_path`
157
+ - `save_config_value(section, key, value)` / `asave_config_value()`
158
+
159
+ ### Logging (`chutils.logger`)
160
+
161
+ - `setup_logger(name, log_level, log_file_name, rotation_type, compress, ...)`
162
+ - Levels: `logger.devdebug` (9), `logger.mediumdebug` (15), and all standard ones.
163
+
164
+ ### Secret Management (`chutils.secret_manager`)
165
+
166
+ - `SecretManager(service_name, prefix)`
167
+ - `save_secret` / `asave_secret`
168
+ - `get_secret` / `aget_secret`
169
+ - `delete_secret` / `adelete_secret`
170
+
171
+ ### Decorators (`chutils.decorators`)
172
+
173
+ - `@log_function_details`: Logs arguments, execution time, and result (uses `DEVDEBUG` level).
174
+
175
+ ## License
176
+
177
+ The project is distributed under the MIT License.
178
+
@@ -0,0 +1,155 @@
1
+ [Русская версия](docs/README_RU.md)
2
+
3
+ # chutils: Stop the Routine!
4
+
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+ [![Python](https://img.shields.io/badge/python-3.9%2B-blue.svg)](https://www.python.org/downloads/)
7
+ [![PyPI version](https://badge.fury.io/py/chutils.svg)](https://badge.fury.io/py/chutils)
8
+ [![Documentation](https://img.shields.io/badge/documentation-read-brightgreen)](https://Chu4hel.github.io/chutils/)
9
+
10
+ **chutils** is a set of simple utilities for Python designed to eliminate the repetitive setup of configuration,
11
+ logging, and secrets in your projects.
12
+
13
+ Start a new project and focus on what matters, not the routine.
14
+
15
+ Full documentation is available on [our website](https://Chu4hel.github.io/chutils/) (currently in Russian).
16
+
17
+ ## The Problem
18
+
19
+ Every time you start a new project, you have to solve the same tasks:
20
+
21
+ - How to conveniently read settings from a configuration file?
22
+ - How to configure logging to write messages to both the console and a file with daily rotation?
23
+ - How to securely store API keys without hardcoding them in the code?
24
+ - How to make it all work "out of the box" without manually defining paths?
25
+
26
+ **chutils** offers ready-made solutions for all these problems.
27
+
28
+ ## Key Features
29
+
30
+ - **✨ Zero Configuration:** The library **automatically** finds your project root and the `config.yml` or `config.ini`
31
+ file. It uses **lazy initialization** — no heavy operations until you actually need them.
32
+ - **⚙️ Flexible Configuration:** Support for `YAML` and `INI` formats. Simple functions for retrieving typed data.
33
+ - **✍️ Advanced Logger:** The `setup_logger()` function configures logging to the console and rotating files out of the
34
+ box. It returns a custom logger with additional debug levels (`devdebug`, `mediumdebug`).
35
+ - **🔒 Secure Secret Storage:** The `secret_manager` module provides a simple interface for saving and retrieving secrets
36
+ via the system `keyring`, with a fallback to `.env` files.
37
+ - **⚡ Async Ready:** Most core functions have asynchronous versions (prefixed with `a`) for non-blocking execution.
38
+ - **🚀 Ready to Use:** Just install and use.
39
+
40
+ ## Installation
41
+
42
+ ```bash
43
+ poetry add chutils
44
+ ```
45
+
46
+ Or using pip:
47
+
48
+ ```bash
49
+ pip install chutils
50
+ ```
51
+
52
+ ## Examples
53
+
54
+ In the [`/examples`](./examples/) folder, you will find ready-to-run scripts demonstrating the library's key features.
55
+ Each example focuses on a specific task.
56
+
57
+ ## Quick Start
58
+
59
+ ### 1. Working with Configuration
60
+
61
+ 1. (Optional) Create a `config.yml` file in your project root:
62
+
63
+ ```yaml
64
+ # config.yml
65
+ Database:
66
+ host: localhost
67
+ port: 5432
68
+ ```
69
+
70
+ 2. Get values in your code:
71
+
72
+ ```python
73
+ from chutils import get_config_value, get_config_int
74
+
75
+ db_host = get_config_value("Database", "host", fallback="127.0.0.1")
76
+ db_port = get_config_int("Database", "port", fallback=5432)
77
+ ```
78
+
79
+ #### Overriding Configuration with Local Files (`config.local.yml`)
80
+
81
+ You can create a `config.local.yml` next to your main file. Values from the local file will **override**
82
+ corresponding values from the main file. This is perfect for local development or storing sensitive data (ensure
83
+ `*.local.*` is in your `.gitignore`).
84
+
85
+ ### 2. Logging Setup
86
+
87
+ 1. Configure and use the logger:
88
+
89
+ ```python
90
+ from chutils import setup_logger, ChutilsLogger
91
+
92
+ # Automatically reads settings from [Logging] section in config.yml
93
+ logger: ChutilsLogger = setup_logger()
94
+
95
+ logger.info("Application started.")
96
+ logger.devdebug("Deep debug message (level 9).")
97
+ ```
98
+
99
+ #### Controlling Logging via Environment Variables
100
+
101
+ - `CH_LOG_NO_TIME=true`: Removes the date/time from the log format (for clean Docker logs).
102
+ - `CH_LOG_NO_FILE=true`: Disables creating log files.
103
+
104
+ These variables have **highest priority** and override any code or config settings.
105
+
106
+ ### 3. Secret Management
107
+
108
+ `SecretManager` looks for secrets in the following order: **Keyring > .env File > Environment Variables**.
109
+
110
+ ```python
111
+ from chutils import SecretManager
112
+
113
+ secrets = SecretManager("my_awesome_app")
114
+
115
+ # Save once
116
+ secrets.save_secret("API_KEY", "secret-value-123")
117
+
118
+ # Use everywhere
119
+ key = secrets.get_secret("API_KEY")
120
+ ```
121
+
122
+ #### Disabling Keyring (Optional)
123
+
124
+ In environments like Docker or CI/CD where `keyring` is unavailable, you can suppress warnings and skip the check:
125
+
126
+ - Set `CH_DISABLE_KEYRING_WARNING=true` in environment.
127
+ - Or add `disable_keyring: true` under `secrets` section in `config.yml`.
128
+
129
+ ## API Overview
130
+
131
+ ### Configuration (`chutils.config`)
132
+
133
+ - `get_config_value(section, key, fallback)` / `aget_config()`
134
+ - `get_config_int`, `get_config_boolean`, `get_config_list`, `get_config_path`
135
+ - `save_config_value(section, key, value)` / `asave_config_value()`
136
+
137
+ ### Logging (`chutils.logger`)
138
+
139
+ - `setup_logger(name, log_level, log_file_name, rotation_type, compress, ...)`
140
+ - Levels: `logger.devdebug` (9), `logger.mediumdebug` (15), and all standard ones.
141
+
142
+ ### Secret Management (`chutils.secret_manager`)
143
+
144
+ - `SecretManager(service_name, prefix)`
145
+ - `save_secret` / `asave_secret`
146
+ - `get_secret` / `aget_secret`
147
+ - `delete_secret` / `adelete_secret`
148
+
149
+ ### Decorators (`chutils.decorators`)
150
+
151
+ - `@log_function_details`: Logs arguments, execution time, and result (uses `DEVDEBUG` level).
152
+
153
+ ## License
154
+
155
+ The project is distributed under the MIT License.
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "chutils"
3
- version = "2.4.0"
3
+ version = "2.5.0"
4
4
  description = "Набор простых и удобных утилит для Python, который избавляет от рутины при работе с конфигурацией и логированием в новых проектах."
5
5
  authors = ["Chu4hel <sergeiivanov636@gmail.com>"]
6
6
  license = "MIT"
@@ -30,17 +30,27 @@ exclude = [
30
30
  python = ">=3.9, !=3.9.0, !=3.9.1"
31
31
  keyring = "^25.7.0"
32
32
  pyyaml = "^6.0.3"
33
- python-dotenv = "^1.2.1"
34
- dotenv = "^0.9.9"
33
+ python-dotenv = [
34
+ { version = "1.2.1", python = "<3.10" },
35
+ { version = "^1.2.2", python = ">=3.10" }
36
+ ]
35
37
 
36
38
 
37
39
  [tool.poetry.group.dev.dependencies]
38
- pytest = "^8.4.2"
40
+ pytest = [
41
+ { version = "^8.4.2", python = "<3.10" },
42
+ { version = "^9.0.2", python = ">=3.10" }
43
+ ]
39
44
  pytest-mock = "^3.15.1"
40
- pyfakefs = "^5.10.0"
45
+ pyfakefs = [
46
+ { version = "^5.10.0", python = "<3.10" },
47
+ { version = "^6.1.5", python = ">=3.10" }
48
+ ]
41
49
  mkdocs = "^1.6.1"
42
- mkdocs-material = "^9.6.22"
43
- mkdocstrings = {extras = ["python"], version = "^0.30.1"}
50
+
51
+ mkdocs-material = "^9.7.5"
52
+ mkdocstrings = { extras = ["python"], version = "^0.30.1" }
53
+ pytest-cov = "^7.0.0"
44
54
 
45
55
  [build-system]
46
56
  requires = ["poetry-core>=2.0.0,<3.0.0"]