Skip to main content

A python library that implements many small tools that are often used in python development.

Project description

🧰 ten-utils

A Python toolkit with commonly used development utilities: logging, in-memory buffers, env variable loading, and more — designed to reduce boilerplate and accelerate development.

PyPI version License Python Downloads


✨ Features

  • ✅ Structured logging with file support(at the time of version 0.0.10 the file saving functionality has not yet been implemented)
  • ✅ Memory-based buffer system
  • ✅ Env file loading with type validation
  • 🛠️ More utilities coming soon...

📦 Installation

You can install ten-utils using pip:

pip install ten-utils

Or with development tools:

pip install ten-utils[dev]

🚀 Quick Start

So far, the library has a few utilities like this:

  • log - Utility for logging any actions in the code. The tool implements the main class Logger and the class for configuration of the main class LoggerConfig.
  • buffer - A utility that creates a value inside the program memory and stores it until it is disabled or intentionally deleted by the user using a method.
  • env_loader - A utility for loading and validating environment variables using a .env file.

Quick start for log utility

from ten_utils.log.logger import Logger
from ten_utils.log.config import LoggerConfig


# Set global configuration
LoggerConfig().set_default_level_log(1)       # Set minimum level to INFO
LoggerConfig().set_save_log_to_file(False)    # Don't write to file

# Create logger instance
logger = Logger(__name__)  # or any other logger name

# Logging
logger.debug("This is a debug message")     # Will be ignored (default = INFO)
logger.info("App started successfully")
logger.warning("This is a warning")
logger.error("An error occurred")

You can also change the configuration at any time within the code. A new instance of the Logger class will use the new configuration you set, while an old instance of the Logger class will use the old configuration.

from ten_utils.log.logger import Logger
from ten_utils.log.config import LoggerConfig


LoggerConfig().set_default_level_log(1)       # Set minimum level to INFO
LoggerConfig().set_save_log_to_file(False)    # Don't write to file

# Create logger instance
logger = Logger(__name__)

# Logging
logger.debug("This is a debug message")     # Will be ignored (default = INFO)
logger.info("App started successfully")
logger.warning("This is a warning")
logger.error("An error occurred")

# Installing a new configuration
LoggerConfig().set_default_level_log(2)       # Set minimum level to WARNING
LoggerConfig().set_save_log_to_file(True)     # Enable file output

# Creating a new instance
logger1 = Logger(__name__)

# Logging
logger1.debug("This is a debug message 1")     # Will be ignored (default = WARNING)
logger1.info("App started successfully 1")     # Will be ignored (default = WARNING)
logger1.warning("This is a warning 1")
logger1.error("An error occurred 1")

Warning:

  • Logs will not be saved to a file, because at the time of v0.0.10 this is not yet implemented.

It's also worth talking about the logger.critical methods:

from ten_utils.log.logger import Logger
from ten_utils.log.config import LoggerConfig


LoggerConfig().set_default_level_log(4)     # Set minimum level to CRITICAL

logger = Logger(__name__)

logger.critical("Critical log!")

There is an important point that when logger.critical is triggered, the programme crashes with the message: Process finished with exit code 1. This behaviour occurs because logger.critical executes exit(1) at the end of execution.

Quick start for buffer utility

from ten_utils.buffer import Buffer


buffer = Buffer()

# Set a value named 'Test' with a value of 'True'.
buffer.set("Test", True)

# Getting value from buffer
value = buffer.get("Test")
print(value)

# Clearing the entire buffer
buffer.clear()

Info:

  • The Buffer class is implemented using the metaclass Singleton. Therefore an instance of the Buffer class can be initialised once and used throughout the programme

Quick start for env_loader utility

from ten_utils.env_loader import EnvLoader

# Create instance and load .env file
env_loader = EnvLoader(".env")

# Reading environment variables
db_name = env_loader.load("DB_NAME", str)
port = env_loader.load("PORT", int)
is_active = env_loader.load("IS_ACTIVE", bool)
allowed_hosts = env_loader.load("ALLOWED_HOSTS", list)

print(db_name, port, is_active, allowed_hosts)

Example .env file:

DB_NAME=mydatabase
PORT=5432
IS_ACTIVE=true
ALLOWED_HOSTS=localhost,127.0.0.1,example.com

🧪 Running Tests

pytest tests/ --disable-warnings -v

To install test/dev dependencies:

pip install ten-utils[dev]

📜 License

This project is licensed under the MIT License — see the LICENSE file for details.


👤 Author

Александр Караваев
Email
GitHub Profile


💡 Contributing

Contributions, issues and feature requests are welcome!
Feel free to open a discussion or a pull request.

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

ten_utils-0.0.10.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

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

ten_utils-0.0.10-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file ten_utils-0.0.10.tar.gz.

File metadata

  • Download URL: ten_utils-0.0.10.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.0

File hashes

Hashes for ten_utils-0.0.10.tar.gz
Algorithm Hash digest
SHA256 f90194a9587e0cbc6dca7e78048fcf497099c907e5c05fc88388ad7e174c2bc7
MD5 7bb4062d3024bd5d332e5dc5e8a5f59a
BLAKE2b-256 ec8766265d4a1d535c83ba619a5f087087ec1dbeeeac17b1be325ea3eb0ff64e

See more details on using hashes here.

File details

Details for the file ten_utils-0.0.10-py3-none-any.whl.

File metadata

  • Download URL: ten_utils-0.0.10-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.0

File hashes

Hashes for ten_utils-0.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 c2c56de8e010ff680416542da562d0c73857c27c06a17ff7ca74d20188b6f9df
MD5 2e0e30ec8b19731ee9e3911fa1b6786c
BLAKE2b-256 03c0f01efdb2d460d9e1895c92dbb8e0304a892a7d02c0bf5394b7760877991a

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