The firebird-base package is a set of Python 3 modules commonly used by Firebird Project in various development projects (for example the firebird-driver). However, these modules have general applicability outside the scope of development for Firebird RDBMS.
Common data types¶
types module provides collection of classes and other types that are often used by
other library modules or applications.
Errorthat is intended to be used as a base class of all application-related errors. The important difference from
Exceptionclass is that
Erroraccepts keyword arguments, that are stored into instance attributes with the same name.
Singletonbase class for singletons.
Distinctabstract base class for classes (incl. dataclasses) with distinct instances.
custom string types.
Various collection types¶
collections module provides data structures that behave much like builtin
dict types, but with direct support of operations that can use structured data stored in
container, and which would normally require utilization of
functools or other
All containers provide next operations:
filterfalsethat return generator that yields items for which expr is evaluated as True (or False).
findthat returns first item for which expr is evaluated as True, or default.
containsthat returns True if there is any item for which expr is evaluated as True.
occurrencethat returns number of items for which expr is evaluated as True.
reportthat returns generator that yields data produced by expression(s) evaluated on list items.
Individual collection types provide additional operations like splitting and extracting based on expression etc.
Expressions used by these methods could be strings that contain Python expression referencing the collection item(s), or lambda functions.
Data conversion from/to string¶
While Python types typically support conversion to string via builtin
str() function (and
__str__ methods), there is no symetric operation that converts string created by
str() back to typed value. Module
strconv provides support for such symetric conversion
from/to string for any data type.
Symetric string conversion is used by
config module, notably by
DataclassOption. You can extend the range of data types supported by these options by
registering convertors for required data types.
configuration options of various data type, including lists and other complex types
direct manipulation of configuration values
reading from (and writing into) configuration in
exchanging configuration (for example between processes) using Google protobuf messages
Memory buffer manager¶
buffer provides a raw memory buffer manager with convenient methods to read/write
data of various data type.
hooks provides a general framework for callbacks and “hookable” events, that
supports multiple usage strategies.
The context-based logging:
Adds context information (defined as combination of topic, agent and context string values) into
LogRecord, that could be used in logging message.
Adds support for f-string message format.
Allows assignment of loggers to specific contexts. The
LoggingManagerclass maintains a set of bindings between
Loggerobjects and combination of
topicspecifications. It’s possible to bind loggers to exact combination of values, or whole sets of values using
ANYsentinel. It means that is possible to assign specific Logger to log messages for particular agent in any context, or any agent operating in specific context etc.
Trace/audit for class instances¶
The trace logging is performed by
traced decorator. You can use this decorator directly,
TracedMixin class to automatically decorate methods of class instances on creation.
Each decorated callable could log messages before execution, after successful execution or
on failed execution (when unhandled execption is raised by callable). The trace decorator
can automatically add
context information, and include parameters passed to
callable, execution time, return value, information about raised exception etc. to log messages.
The trace logging is managed by
TraceManager, that allows dynamic configuration of traced
callables at runtime.
Registry for Google Protocol Buffer messages and enums¶
protobuf provides central registry for Google Protocol Buffer messages and enums.
*_pb2.py protobuf files could be registered using
load_registered function. The registry could be then used to obtain information about
protobuf messages or enum types, or to create message instances or enum values.