This quickstart shows a realistic small workflow that uses the most important parts of clevertools together:
- package-wide defaults with
configure() - logger setup with
configure_logger() - safe output with
mask() - structured file I/O with
write_json()andread_json() - merged configuration with
load_config()
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,
"file_logging_enabled": True,
"file_log_path": "logs/app.log",
},
)
logger = configure_logger(name="demo", use_colors=False)
payload = {
"service": "billing",
"environment": "dev",
"token": mask("sk-demo-123456789", 4, 3),
}
write_json("tmp/config.json", payload, indent=2, ensure_ascii=False)
loaded = read_json("tmp/config.json")
logger.info("Loaded payload: %s", loaded)
config = load_config("config/base.toml", "config/local.yaml")
logger.info("Billing enabled: %s", config.get("features.billing.enabled"))configure()stores defaults for error handling and logger setup.configure_logger()builds the final logger from those defaults.mask()hides the sensitive part of the token before it is written anywhere.write_json()writes a formatted JSON file and creates parent folders if needed.read_json()loads the file again.load_config()merges several config files into one object with attribute access and dot-path lookups.
from clevertools import read, write
write("tmp/notes.txt", "Hello from clevertools")
content = read("tmp/notes.txt")
print(content)from clevertools import read_toml, write_yaml
settings = read_toml("settings.toml", on_error="raise")
write_yaml("build/settings.yaml", settings, sort_keys=False)from clevertools import configure_logger, log
configure_logger(level="INFO", console_enabled=True, use_colors=False)
log.info("script started")