Skip to main content

PythonByzaticCommons

PythonByzaticCommons is a modular utility library for Python that provides a collection of reusable components for file reading, exception handling, logging, in-memory storage, singleton management, and more. Designed for extensibility and clean architecture, it helps accelerate development by offering ready-to-use patterns and interfaces.

Artifact available on pypi:
https://pypi.org/project/python-byzatic-commons

pip install python-byzatic-commons

Modules Overview

exceptions

A set of structured exception classes to formalize error handling in complex systems.

  • BaseErrorException: Root base class for domain-specific exceptions.
  • OperationIncompleteException: Indicates partial success or failure in operations.
  • ExitHandlerException: Used to trigger early exit logic in controlled flows.
  • CriticalErrorException: Raised for non-recoverable fatal errors.
  • NotImplementedException: Placeholder for yet-to-be-implemented logic.
from python_byzatic_commons.exceptions import OperationIncompleteException
from python_byzatic_commons.exceptions import ExitHandlerException


def main():
    try:
      ...
    except OperationIncompleteException as oie:
        raise ExitHandlerException(oie.args, errno=oie.errno, exception=oie)
    except Exception as e:
        raise ExitHandlerException(e.args, exception=e)
    except KeyboardInterrupt as ki:
        raise ExitHandlerException(ki.args, exception=ki)


if __name__ == '__main__':
    main()

filereaders

Unified interfaces and concrete implementations for parsing configuration files.

  • Interfaces:

    • BaseReaderInterface: Defines contract for readers returning a dict from a file.
  • Readers:

    • JsonFileReader: Loads .json files into Python dictionaries.
    • YamlFileReader: Loads .yaml/.yml files using PyYAML.
    • ConfigParserFileReader: Loads .ini-style config files using configparser.

All readers validate input paths and support standard Python error handling.

import os
import sys
from python_byzatic_commons.filereaders import JsonFileReader
from python_byzatic_commons.filereaders.interfaces import BaseReaderInterface


def main():
    runtime_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
    logger_config_file_path_json = os.path.join(
        runtime_dir,
        'configuration',
        'configuration.json'
    )
    
    reader: BaseReaderInterface = JsonFileReader()
    config: dict = reader.read(logger_config_file_path_json)
    print(config)


if __name__ == '__main__':
    main()

in_memory_storages

In-memory key-value storage layer with interchangeable implementations and management.

  • Interfaces:

    • KeyValueDictStorageInterface, KeyValueListStorageInterface, etc.
  • Storages:

    • KeyValueDictStorage: Uses dict internally.
    • KeyValueListStorage: Uses list for indexed access.
    • KeyValueObjectStorage: Stores arbitrary Python objects.
    • KeyValueStringStorage, KeyValueModuleTypeStorage, etc.
  • Manager:

    • StoragesManager: Central registry and access point for storage instances.

Test coverage is included in the test/ directory.

from python_byzatic_commons.in_memory_storages.interfaces import KeyValueDictStorageInterface
from python_byzatic_commons.in_memory_storages.key_value_storages.KeyValueDictStorage import KeyValueDictStorage


# create an in-memory dictionary storage
storage: KeyValueDictStorageInterface = KeyValueDictStorage("MyAwsomeStorage")

# create entries
storage.create("foo", {"value": 123})
storage.create("bar", {"value": 456})

# read entry
print(storage.read("foo"))  # → {'value': 123}

# update entry
storage.update("foo", {"value": 999})

# check existence
if storage.contains("foo"):
    print("Entry 'foo' exists!")

# read all
print(storage.read_all())  # → {'foo': {'value': 999}, 'bar': {'value': 456}}

# delete one
storage.delete("bar")

# drop all
storage.drop()

logging_manager

Encapsulates logging configuration and output.

  • LoggingManagerInterface: Describes basic logging interface (info, warn, error, etc.)
  • LoggingManager: Concrete implementation wrapping Python’s built-in logging module with a consistent configuration.

Supports colored output, custom formatters, and stream redirection.

import os
import sys
import logging
from python_byzatic_commons.logging_manager import LoggingManager
from python_byzatic_commons.logging_manager.interfaces import LoggingManagerInterface


def main():
    runtime_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
    logger_config_file_path_json = os.path.join(
        runtime_dir,
        'configuration',
        'logger_configuration.json'
    )

    logging_manager: LoggingManagerInterface = LoggingManager()
    logging_manager.init_logging(
        logger_config_file_path_json,
        "JSON"
    )
    
    logger = logging.getLogger("Application-logger")
    
    logger.debug("some debug")


if __name__ == '__main__':
    main()
import logging

class SomeClass(object):
    __some_var: list

    def __init__(self, some_var: list):
        self.__logger = logging.getLogger(f"{type(self).__name__}")
        self.__some_var: list = some_var

    def some_method(self, some_other_var: str) -> None:
      self.__logger.debug(f"some_other_var= {some_other_var}")
      self.__logger.debug(f"some_var= {self.__some_var}")

singleton

Provides a class-based singleton pattern.

  • Singleton: A metaclass-based implementation that ensures a class has only one instance across the application.

Useful for shared services like loggers, configuration managers, etc.

from python_byzatic_commons.singleton import Singleton

class SomeClass(Singleton):
    . . .

License

This project is licensed under the terms of the Apache 2.0 license.

Metadata

Release files for python-byzatic-commons 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-byzatic-commons 1.0.2
File Size Uploaded
python_byzatic_commons-1.0.2.tar.gz 31.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for python-byzatic-commons 1.0.2
File Interpreter ABI Platform
python_byzatic_commons-1.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 92.4 kB

Release files / python_byzatic_commons-1.0.2.tar.gz

Download URL python_byzatic_commons-1.0.2.tar.gz
Size 31.7 kB
Tags Source
SHA-256 checksum
How to use checksums
b9d11eff8aee3802f777ec7ee9c826be84d72d31f94b5dfe843d61c5b728b01e
BLAKE2b-256 checksum
How to use checksums
e2b2a12264ddae9b2511f8fb5411c1746a56fa33419794ab589c7e8da907fe6e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.0

Release files / python_byzatic_commons-1.0.2-py3-none-any.whl

Download URL python_byzatic_commons-1.0.2-py3-none-any.whl
Size 60.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ee6496d8de758b9f3eb0ea3dbcbbb7f8dd44479aa6af8bc2b7d4f118441d6d8b
BLAKE2b-256 checksum
How to use checksums
60c9aa44e437a394927f63d083d6ba28053dd1f3fd0500f240b1592f9c085e4c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.0

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page