Moooove your data with ease using our udderly simple pipeline framework.
Project description
Carabao
+:
- *-
-* +--
-* *=:
-=* +=+-
-+* +==*-
++=* **=+-
*==*+ -**==*-
-***=*++ -*=**=**-%
%-****=*===----------#*%*##+%#@#**-*---------===**+=-%-#
**=-***-=*==*==--****%#%%@*@@%#*-----+*=++%++++%%*
*%%%#%####%##%*#%%=##@++%@%%######%%%%#%@
+ @%@@@@##%#=@#@@+++@@%
--+++++##%@%#=@@+@@%%@#@#++++=%
@+*@@@@@@##@##*=**+*@%%%@#@+@@#@++%
#* *#**##+#%%%*@ %%%%++++#+
*+****+#%%%*@
**=*==+#%##*
*=*=+*#%#*
#=*****#*
#@=***#@##
%%=%%%#=#%#
####%%%#
A Python library for building robust publisher-subscriber (pub/sub) frameworks with built-in lanes for common tasks.
Features
- Core framework for managing pub/sub systems based on l2l (lane2lane)
- Built-in lanes for:
- Database logging (
LogToDB) - Records exceptions to MongoDB - Network health monitoring (
NetworkHealth) - Tracks network ping times - Environment variable display (
PrettyEnv) - Formats environment variables for debugging
- Database logging (
- Automatic configuration management with settings system
- Error handling with custom error handlers
- Clean shutdown with exit handlers
- Command-line interface for management, including interactive selection
- Support for multiple database connections (MongoDB, Redis, Elasticsearch, PostgreSQL)
- Development and production mode support
- Test mode for safe testing in production environments
Installation
pip install carabao
Requirements
- async-timeout
- dnspython
- fun-things
- generic-lane
- lazy-main
- python-dotenv
- simple-chalk
- typing-extensions
Usage
Basic Usage
The framework is started using the CLI commands:
# For development mode
moo dev [queue_name]
# For production mode
moo run
No import statement is needed to start the framework.
Environment Variables
Carabao uses the following environment variables:
QUEUE_NAME: (Required) Name of the queue to consumeCARABAO_AUTO_INITIALIZE: Controls automatic initializationCARABAO_AUTO_START: Controls automatic startingCARABAO_START_WITH_ERROR: Whether to start even if errors occurredSINGLE_RUN: Run once then exit ifTrueTESTING: Enable debug logging ifTrue
Environment Files
Carabao supports environment variables loaded from .env files using python-dotenv:
.env.development: Used when running in development mode (moo dev).env.release: Used when running in production mode (moo run).env: Used as a fallback if neither of the above files exists
When initializing a new project with moo init, these files are automatically created.
The framework prioritizes environment variables in the following order:
- Variables defined in the system environment
- Variables defined in the appropriate .env file
- Default values defined in settings
This makes it easy to maintain different configurations for development, testing, and production environments without changing code.
Settings System
Carabao uses a centralized Settings system for configuration management. The Settings class provides a unified interface for accessing configuration values throughout the application.
Setting Up settings.py
A typical settings.py file inherits from the base Settings class:
from carabao import Settings as S
class Settings(S):
# Directory where the lane modules are stored
LANE_DIRECTORIES = [
"lanes",
]
# Whether to run the pipeline once and exit
SINGLE_RUN = False
# Minimum and maximum sleep times between runs (in seconds)
SLEEP_MIN = 1.0
SLEEP_MAX = 3.0
# Whether to exit when processing is finished
EXIT_ON_FINISH = False
# Delay before exiting (in seconds)
EXIT_DELAY = 0.0
# Number of parallel processes to use
PROCESSES = 1
# Whether to deploy safely in production
DEPLOY_SAFELY = True
# Custom error handler function
@classmethod
def error_handler(cls, error: Exception) -> None:
"""
Custom error handler for the application.
Args:
error: The exception that was raised.
"""
print(f"An error occurred: {error}")
@classmethod
def before_start(cls) -> None:
"""
Hook method called before framework startup.
"""
# Perform any necessary initialization
pass
When you run moo init, this file is automatically created for you in the appropriate location.
Settings Configuration
-
carabao.cfg File: The framework uses a configuration file to locate your settings module:
[directories] settings = src.settings # or path.to.your.settings -
Accessing Settings in Code: To use these settings in your code:
from carabao.settings import Settings settings = Settings.get() value = settings.value_of("LANE_DIRECTORIES")
-
Available Settings: Common settings include:
LANE_DIRECTORIES: List of directories to search for lane definitionsSINGLE_RUN: Whether to run lanes once or continuouslySLEEP_MIN,SLEEP_MAX: Minimum and maximum sleep times between runsEXIT_ON_FINISH: Whether to exit after finishing processingEXIT_DELAY: Delay before exitingPROCESSES: Number of parallel processes to useDEPLOY_SAFELY: Whether to enforce production safety settings
You can also define your own custom settings and access them the same way.
-
Overriding Settings: Settings can be overridden by environment variables. For example, if your setting is named
SINGLE_RUN, you can override it by setting theSINGLE_RUNenvironment variable.
CLI Usage
Carabao provides a command-line interface for managing lanes:
# Run in production mode
moo run [queue_name]
# Run in development mode
moo dev [queue_name]
# Initialize a new project
moo init [--skip]
# Create a new lane
moo new [lane_name]
The development mode (dev) command:
- If no queue name is provided, displays an interactive curses-based menu to select from available lanes
- Highlights the last run queue
- Provides navigation with arrow keys
- Allows selection with Enter key
- Exit option at the bottom
Development
Creating a New Project
You can quickly initialize a new project with:
moo init
This will set up the necessary directory structure and configuration files.
Creating a New Lane
To create a new lane for processing:
moo new MyLaneName
This will generate a file with proper naming conventions (snake_case for the filename, PascalCase for the class name).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file carabao-1.22.2.tar.gz.
File metadata
- Download URL: carabao-1.22.2.tar.gz
- Upload date:
- Size: 31.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dc3ffa93792bb79749e5dcae8c21dbb1fdc9a24e6a1f41969ab973c2390f348f
|
|
| MD5 |
5d68efeccf7b549d17b0fe966b5f2bf3
|
|
| BLAKE2b-256 |
3bc1ef072ec774303f441f9f4d9c089d4623701cb400c2633b1354071196fcb6
|
File details
Details for the file carabao-1.22.2-py3-none-any.whl.
File metadata
- Download URL: carabao-1.22.2-py3-none-any.whl
- Upload date:
- Size: 37.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fda0bd2f73b64bacaf72225e826a44e2fa2430bf358d6c0248520003c0c352f3
|
|
| MD5 |
59d9e8615b5f771912479406e1289206
|
|
| BLAKE2b-256 |
baaf210fa8e6fc9b95e281229c68d2a217bfd66dc373b57861c0d6b21e593652
|