Shared Redis, MongoDB, and healthcheck runtime helpers for EB services
Project description
OS.py EB Runtime Library
Shared runtime helpers for EB services:
- Redis client setup and reconnect wrappers
- MongoDB client setup and reconnect wrappers
- Reusable healthcheck servers (async TCP and threaded HTTP)
Author: Oleg Smirnov
Installation
From GitHub
pip install git+https://github.com/BestianCode/os.py.lib.eb.git
Development
git clone https://github.com/BestianCode/os.py.lib.eb.git
cd os.py.lib.eb
pip install -e .
Modules
os_eb.os_redis
validate_redis_url(redis_url)build_async_redis(redis_url, ...)reconnect_async_redis(current_client, redis_url, ...)call_with_reconnect(get_client, set_client, redis_url, op_name, *args, **kwargs)
os_eb.os_mongo
is_mongo_connection_error(exc)build_async_mongo_client(mongodb_uri, **kwargs)reconnect_async_mongo(current_client, mongodb_uri, **kwargs)build_sync_mongo_client(mongodb_uri, **kwargs)reconnect_sync_mongo(current_client, mongodb_uri, **kwargs)
os_eb.os_health
parse_cidrs(raw)is_ip_allowed(ip_raw, allowed_networks)AsyncHealthServerfor async workersThreadedHealthServerfor sync workers- configurable paths:
health_path,dbhealth_path
- configurable paths:
Example
from os_eb.os_redis import build_async_redis, call_with_reconnect
redis = build_async_redis("redis://localhost:6379/0")
async def get_client():
return redis
async def set_client(new_client):
global redis
redis = new_client
await call_with_reconnect(
get_client=get_client,
set_client=set_client,
redis_url="redis://localhost:6379/0",
op_name="xadd",
op_args=("stream:name", {"k": "v"}),
)
Health paths from env:
import os
from os_eb.os_health import AsyncHealthServer
server = AsyncHealthServer(
bind_host="0.0.0.0",
port=8080,
allowed_networks=[],
dbhealth_provider=my_dbhealth_provider,
health_path=os.getenv("HEALTHCHECK_PATH", "/alive"),
dbhealth_path=os.getenv("DBHEALTHCHECK_PATH", "/dlive"),
)
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
os_py_lib_eb-1.0.0.tar.gz
(7.3 kB
view details)
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 os_py_lib_eb-1.0.0.tar.gz.
File metadata
- Download URL: os_py_lib_eb-1.0.0.tar.gz
- Upload date:
- Size: 7.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bdeae4bbea226264d50b6220b7f43eec3cf1432a29ae58e7a5c49c6dc6be055a
|
|
| MD5 |
ec7502a20704bd1280d45d1545e0f855
|
|
| BLAKE2b-256 |
e0456f9b2eef7a9b7c3c4ccbe19033d6eb5d43b491a853827beb2e7a1b0ab518
|
File details
Details for the file os_py_lib_eb-1.0.0-py3-none-any.whl.
File metadata
- Download URL: os_py_lib_eb-1.0.0-py3-none-any.whl
- Upload date:
- Size: 6.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
baf0b4ba5f976f8a87b75f8f349f166c77389175de4bb58731e8558357e1ce6b
|
|
| MD5 |
48d6e0a9d209cf0d32eb0ce08690e2c2
|
|
| BLAKE2b-256 |
8b6215f59a80c2da61be191aaa79e9ff49450d6ea4c0da8d8a89d20c9b9298e8
|