Compact Python utility library for file I/O, config loading, sensitive-value masking, and ready-to-use logging.
Project description
clevertools
clevertools is a practical Python helper library for everyday application code. It focuses on the boring but important parts that show up in many projects: reading and writing files, handling JSON/TOML/YAML, masking sensitive values, loading split configuration, and setting up logging without repetitive boilerplate.
The package is intentionally small, but it still gives you enough structure that a new teammate can open the project and understand how configuration, file access, and logging are supposed to work.
What clevertools is for
Use clevertools when you want:
- a consistent way to read and write text, bytes, JSON, TOML, and YAML
- one shared error-handling model across helpers
- simple masking for API keys, tokens, emails, IDs, and similar values
- merged configuration from multiple files with dot access
- fast logger setup for console and file logging
- lower-level logging primitives when you need custom control
What is included
Core helpers
configure()stores package-wide defaults such as error handling and logger overrideslogis the shared default loggermask()partially hides sensitive strings before you log or display them
File helpers
read()andwrite()handle plain text and raw bytesensure_file()andensure_dir()make sure file and directory paths existread_json()andwrite_json()handle JSON filesread_toml()andwrite_toml()handle TOML filesread_yaml()andwrite_yaml()handle YAML filesload_config()merges multiple config files into one object
Logging helpers
configure_logger()creates or refreshes a logger with console and file handlersstart_file_logger()captures early startup output before final logger setup is readystop_file_logger()restores capturedstdoutandstderrget_logger()returns a named logger without modifying itCleverToolsFormatteradds structured time fields and optional colorsbuild_console_handler()andbuild_file_handler()expose the low-level handler buildersreset_handlers()safely clears existing handlersresolve_logger_options()shows the final logger settings after overrides are applied
Quick example
from clevertools import (
configure,
configure_logger,
load_config,
mask,
read_json,
write_json,
)
configure(
error_mode="raise",
logger_overrides={
"level": "INFO",
"format_preset": "datetime",
"console_enabled": True,
},
)
logger = configure_logger(name="billing", use_colors=False)
payload = {
"service": "billing",
"token": mask("sk-demo-123456789", 4, 3),
"retries": 3,
}
write_json("tmp/config.json", payload, indent=2, ensure_ascii=False)
loaded = read_json("tmp/config.json")
logger.info("Loaded config: %s", loaded)
config = load_config("config/base.toml", "config/local.yaml")
logger.info("Feature enabled: %s", config.get("features.billing.enabled"))
Typical workflows
1. Read and write structured files
from clevertools import read_toml, write_yaml
settings = read_toml("settings.toml", on_error="raise")
write_yaml("build/settings.yaml", settings, sort_keys=False)
2. Hide secrets before logging
from clevertools import mask, log
token = "sk-prod-abcdef1234567890"
log.info("Using token %s", mask(token, 5, 4))
3. Merge config from multiple sources
from clevertools import load_config
config = load_config(
"config/defaults.toml",
"config/team.json",
"config/local.yaml",
)
print(config.database.host)
print(config.get("features.search.enabled", False))
4. Set up application logging
from clevertools import configure_logger
logger = configure_logger(
name="worker",
level="INFO",
format_preset="datetime",
console_enabled=True,
file_logging_enabled=True,
file_log_path="logs/worker.log",
file_write_mode="buffered",
use_colors=False,
)
logger.info("worker started")
Error handling model
Most helpers support on_error. If you do not pass it, the package-wide default from configure() is used.
"raise"raises the original exception"log"logs the error and returns the helper's fallback value"silent"suppresses the error and returns the helper's fallback value
Example:
from clevertools import configure, read_json
configure(error_mode="silent")
payload = read_json("missing.json")
print(payload) # None
Documentation map
If this is your first time in the repository, read the docs in this order:
Important reference pages:
- docs/getting-started.md for a guided first run
- docs/tools/README.md for the full API map
- docs/concepts/error-handling.md for shared fallback behavior
- docs/concepts/logging.md for logger architecture and write modes
Repository layout
src/clevertools/contains the library codetests/contains the automated test suitedocs/contains the user-facing documentationREADME.mdis the first overview for new users
Installation
pip install -e .
For a full local setup including virtual environments and dependencies, see docs/installation.md.
Requirements
- Python
>=3.11
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
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 clevertools-1.4.1.tar.gz.
File metadata
- Download URL: clevertools-1.4.1.tar.gz
- Upload date:
- Size: 29.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dce1556ca8366c94330bd0dae0f47473f3a8b3df08b3c751cff55f285cc2c637
|
|
| MD5 |
e1b140a8f4ca14fb696606b28e66beb2
|
|
| BLAKE2b-256 |
64f653bc2e4b206b4fe765522571b5d4e3da6f78349aae2dfbc06bddfd48d0c8
|
File details
Details for the file clevertools-1.4.1-py3-none-any.whl.
File metadata
- Download URL: clevertools-1.4.1-py3-none-any.whl
- Upload date:
- Size: 33.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
31cfdb4b48db6f42c61fee72c76687bacf7c9781c924dbb4c997ca8ffc6728fc
|
|
| MD5 |
513d13e6ddd06a3647191117edebb28e
|
|
| BLAKE2b-256 |
f499d91d16ca617d5f0b2893a6c01334440c97bbd5c89017cdecfc837fb445db
|