Skip to main content

Lynceus is a sophisticated and resilient Python toolbox designed to serve as the foundational core layer of your Python applications. It offers features like configuration file management with inheritance and automatic JSON loading, seamless logger configuration, efficient session management, and unified file handling for both local and remote storage. By providing a plethora of utilities, Lynceus allows developers to skip the mundane setup and focus directly on what truly matters.

Project description

Lynceus

License: GPL v3 Latest Release Pipeline Status Coverage Report PyPI version Python 3.10+

Lynceus is a sophisticated and resilient Python toolbox designed to serve as the foundational core layer of your Python applications. It offers powerful features for configuration management with inheritance, automatic logger configuration, efficient session management, and unified file handling for both local and remote storages.

๐Ÿ“‹ Table of Contents

โœจ Key Features

  • โš™๏ธ Session Management - Efficient session handling with salt-based configuration discovery
  • ๐Ÿ”ง Advanced Configuration Management - Hierarchical configuration with inheritance and JSON loading
  • ๐Ÿ“ Smart Logger Configuration - Automated logger setup with customizable handlers and formatters
  • ๐Ÿ—‚๏ธ Unified File Handling - Seamless local and remote storages management (S3, etc.)
  • ๐Ÿ”— DevOps Integration - Versatile DevOpsAnalyzer abstract layer offering project analysis and statistics, featuring GitLab and GitHub implementations with the flexibility to extend to additional platforms
  • ๐Ÿ“Š Data Processing - Built-in utilities for data analysis and processing
  • ๐Ÿ”’ Secure Authentication - Separate configuration files for sensitive credentials

๐Ÿš€ Installation

Lynceus packages are available on PyPI and can be installed with any package manager of your choice.

As a Dependency (Recommended)

Add Lynceus to your existing project as a dependency:

# Using Poetry
poetry add lynceus

# Using pip
pip install lynceus

# Using uv
uv add lynceus

# Using conda
conda install -c conda-forge lynceus

# Using pipenv
pipenv install lynceus

For detailed installation instructions with Poetry, please refer to the Poetry documentation.

For Contributing to Lynceus

If you want to contribute to Lynceus development:

# Fork/Clone the repository
git clone https://gitlab.com/bertrand-benoit/lynceus.git
cd lynceus

# Install development dependencies
poetry install

# Run tests
poetry run pytest

โš ๏ธ Important: Only clone this repository if you intend to contribute to Lynceus itself. For using Lynceus in your projects, install it as a dependency instead.

๐Ÿ“– Quick Start

Let's refer to your envisioned project as Argo throughout this documentation; as Argo, the legendary vessel of epic adventures in Greek mythology, with Lynceus among its Argonauts.

Then start using Lynceus in your source code:

from logging import Logger

from lynceus.core.lynceus import LynceusSession

# Initialize a session with your project's salt
session: LynceusSession = LynceusSession.get_session(
    salt="argo",
    registration_key={"environment": "production", "service": "api"}
)

# Get logger from session (default prefix is 'Lynceus')
logger: Logger = session.get_logger('task.processor')  # Creates 'Lynceus.task.processor' logger
logger.warning('โš ๏ธ Prepare for departure as Argo vessel is about to set sail! ๐Ÿšข๐Ÿ’จ')

โš™๏ธ Configuration

Lynceus is highly configurable through configuration files. The system uses a salt-based approach to locate the appropriate configuration files for your project.

Salt-Based Configuration with Inheritance

Lynceus supports multiple configuration files that are merged hierarchically. When initializing Lynceus session, you provide a salt (project identifier) that determines which configuration files to load.

The system searches for configuration files, from their relative paths, using lynceus.utils.lookup_root_path(), which iteratively searches up to three directory levels by default.

Configuration Loading Order:

  1. lynceus.default.conf - Core default configuration (embedded in lynceus/misc/ folder of Lynceus package)
  2. {salt}_default.conf - Default configuration for your salt (optional)
  3. {salt}.conf - Main project configuration (optional)
  4. {salt}_storages.conf - Remote storages configuration (optional)
  5. {salt}_credentials.conf - Credentials configuration (optional)

Later configurations override earlier ones, allowing for flexible customization while maintaining sensible defaults.

Configuration File Structure

Create configuration files named with your project's salt, and place them in the root directory or a subdirectory of your project. Ensure the relative path of these files does not exceed three directory levels from any executed Python files. Note: Typically, the {salt}_default.conf file is intended to be packaged with the source code, so it can be placed within a subdirectory of the main package.

All configuration files are optional, for example, here is a possible structure for a project with salt argo:

project_root/
โ”œโ”€โ”€ argo.conf                  # (Optional) Main project configuration
โ”œโ”€โ”€ argo_storages.conf         # (Optional) Remote storages configuration
โ”œโ”€โ”€ argo_credentials.conf      # (Optional) Credentials configuration
โ””โ”€โ”€ argo/                      # Main Python package
    โ””โ”€โ”€ misc/
        โ””โ”€โ”€ argo_default.conf  # (Optional) Default configuration for argo

Basic Configuration

For general configuration, you have the option to place it in either the {salt}.conf file or the {salt}_default.conf file.

{main_package}/misc/{salt}_default.conf (e.g., argo/misc/argo_default.conf):

[General]
# Project information
project_name=Argo Project

[StorageConfiguration]
# Storage settings
remote_storages_conf=argo_storages.conf
work_dir=/tmp/argo_workdir

Logger Configuration

Lynceus supports advanced logger configuration using Python's standard logging system.

{salt}.conf (e.g., argo.conf):

[loggers]
keys = root, argo

[handlers]
keys = file, console_out, console_err

[formatters]
keys = default

[logger_root]
level = DEBUG
handlers = file, console_out, console_err

[handler_file]
class=FileHandler
level=DEBUG
formatter=default
# N.B.: use 'w' to override file each time a process is running, use 'a' to append to potential existing file to avoid log lost.
args=('/tmp/argo.log', 'a')

[handler_console_out]
; N.B.: lynceus.core.logger_utils.FilteredStdoutLoggerHandler is a special class allowing to filter out messages from Warning.
; Thus, with combination of a dedicated 'console error handler' configuration, it allows to have:
;  - warning, error and critical messages log on stderr
;  - the others messages on stdout
class = lynceus.core.logger_utils.FilteredStdoutLoggerHandler
args = (sys.stdout,)
; Overrides console out level to DEBUG, allowing to see DEBUG messages of all logger having corresponding level (including those inherited from previously loaded configuration files).
level = DEBUG
formatter = default

[handler_console_err]
class = StreamHandler
args = (sys.stderr,)
level = WARNING
formatter = default

[formatter_default]
style={
format = {asctime:20} {name:16} {levelname:8} {message}
datefmt = %Y/%m/%d %H:%M:%S

[logger_argo]
; Defines to logs for this logger only from INFO.
level=INFO
handlers=
qualname=argo

Credentials Configuration

For sensitive credentials, you can create a separate configuration file using your salt.

{salt}_credentials.conf (e.g., argo_credentials.conf):

[DevOps-GitLab]
token = glpat-xxxxxxxxxxxxxxxxxxxx

[DevOps-GitHub]
token = ghp-xxxxxxxxxxxxxxxxxxxx

[AWS-S3-Production]
access_key_id=AKIAIOSFODNN7EXAMPLE
secret_access_key=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY

[OVH-S3-Backup]
access_key_id=OVHEXAMPLEKEY
secret_access_key=OVHEXAMPLESECRET

Remote Storages Configuration

For remote storages, you can create a separate configuration file using your salt.

{salt}_storages.conf (e.g., argo_storages.conf):

[StorageConfiguration]
available_remote_storages=AWS-S3-Production,OVH-S3-Backup

[AWS-S3-Production]
storage_type=s3
bucket_name=my-production-bucket
username=my-user
s3_endpoint = https://s3-eu-west-1.amazonaws.com
signature_version = s3v4

[OVH-S3-Backup]
storage_type=s3
bucket_name=my-backup-bucket
username=backup-user
s3_endpoint = https://s3.gra.cloud.ovh.net
region_name = gra
signature_version = s3v4
addressing_style = virtual

Extra Configuration

For any other configuration, you can create any count of configuration files (and request manual loading), or put the configuration inside your {salt}.conf one.

For instance for DevOps integration, configure your project details inside a conf_dir/argo_custom.conf:

[Project]
name=Argo Analytics Project
uri=https://gitlab.com
token=<your-token>
username=Argo Bot
project_path=my-org/argo-analytics
project_profile=SOURCE_CODE_DATA_SCIENCE

For instance for Tests, configure your project details inside a conf_dir/tests/argo_tests.conf:

[Tests-DevOps-Gitlab]
name=Gitlab public project
uri=https://gitlab.com
token=<your-token>
project_path=fdroid/fdroidserver
git_reference=master
project_profile=SOURCE_CODE_DEFAULT

Advanced Usage Examples

from logging import Logger

from lynceus.core.config.lynceus_config import LynceusConfig
from lynceus.core.lynceus import LynceusSession

# Multiple sessions for different services
api_session: LynceusSession = LynceusSession.get_session(
    salt="argo",
    registration_key={"service": "api", "env": "production"},
    root_logger_name="ArgoAPI"
)

worker_session: LynceusSession = LynceusSession.get_session(
    salt="argo",
    registration_key={"service": "worker", "env": "production"},
    root_logger_name="ArgoWorker"
)

# Each session maintains its own logger hierarchy
api_logger: Logger = api_session.get_logger('request.handler')       # 'ArgoAPI.request.handler'
worker_logger: Logger = worker_session.get_logger('task.processor')  # 'ArgoWorker.task.processor'

# Configuration can be read from any session.
storage_work_dir: str = worker_session.get_config('StorageConfiguration', 'work_dir')
worker_logger.info(f'Will create internal files under {storage_work_dir=}')

# Load additional configuration from files
config: LynceusConfig = api_session.get_lynceus_config_copy()
config.lookup_configuration_file_and_update_from_it('conf_dir/argo_custom.conf')
config.lookup_configuration_file_and_update_from_it('conf_dir/tests/argo_tests.conf')

# Configuration can be read directly from any LynceusConfig instance.
devops_uri: str = config.get_config('Tests-DevOps-Gitlab', 'uri')
tests_logger: Logger = worker_session.get_logger('tests')  # 'ArgoWorker.tests'
tests_logger.info(f'Some Gitlab DevOps Tests will be performed on {devops_uri} project')

๐Ÿ“š Documentation

For comprehensive documentation, visit the Complete Technical Documentation directory.

๐Ÿค Contributing

We welcome contributions! Please see Contributing Guide for details.

Don't hesitate to contact me if you need information about:

  • Development environment setup
  • Code standards and best practices
  • Testing procedures
  • Submission process

You can report issues or request features and propose merge requests.

๐Ÿ“œ License

This project is licensed under the GNU General Public License v3.0 (GPL-3.0).

Key points about GPL-3.0:

  • Free to use, modify, and distribute
  • Source code must be made available when distributing
  • Modifications must also be GPL-3.0 licensed
  • No warranty provided

For complete license terms, see the LICENSE file or visit https://www.gnu.org/licenses/gpl-3.0.

๐Ÿ”— Links


Built with โค๏ธ for the open source community

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

lynceus-1.2.2.tar.gz (52.6 kB view details)

Uploaded Source

Built Distribution

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

lynceus-1.2.2-py3-none-any.whl (60.7 kB view details)

Uploaded Python 3

File details

Details for the file lynceus-1.2.2.tar.gz.

File metadata

  • Download URL: lynceus-1.2.2.tar.gz
  • Upload date:
  • Size: 52.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.13.5 Linux/6.8.0-49-generic

File hashes

Hashes for lynceus-1.2.2.tar.gz
Algorithm Hash digest
SHA256 325fd30fa261e1eb7b77eeebe35be6ffe627c63f3d8b940915e557d0eda1f389
MD5 b688cfc1bd2f06c44689e0b7b0aaaadf
BLAKE2b-256 e0746ea70cb84e949e3872f8e9752c96a3b2ee667e91c33f5f3aeabd0992c9a9

See more details on using hashes here.

File details

Details for the file lynceus-1.2.2-py3-none-any.whl.

File metadata

  • Download URL: lynceus-1.2.2-py3-none-any.whl
  • Upload date:
  • Size: 60.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.13.5 Linux/6.8.0-49-generic

File hashes

Hashes for lynceus-1.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3297e36559489de28795a2a1213b7f9f460420fc4577bf18274482aeef4c466c
MD5 9df99dd83e14ba06fc64b51ea6bda59b
BLAKE2b-256 15e7b87d51bc7b6013446859d6af3d96f25b8ff20a1a779fafe898c8015841aa

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