Skip to main content

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)
  • Unified console logging formatter

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)
  • AsyncHealthServer for async workers
  • ThreadedHealthServer for sync workers
    • configurable paths: health_path, dbhealth_path

os_eb.os_logging

  • configure_console_logging(level="INFO", force=True)
  • output format:
    • YYYY-MM-DD HH:MM:SS.mmm - LEVEL - HOSTNAME - message

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


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.1.0.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

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

os_py_lib_eb-1.1.0-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file os_py_lib_eb-1.1.0.tar.gz.

File metadata

  • Download URL: os_py_lib_eb-1.1.0.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for os_py_lib_eb-1.1.0.tar.gz
Algorithm Hash digest
SHA256 c536a7fe3915d9ac3324350352acfdbc428a57c58c399d67a9d8f9b476633832
MD5 efa2bcb538d6d622a0627e18c36dfc44
BLAKE2b-256 1290e4b7c9c27066c95f66c9591e4ad6c29771ad720fd220ff5fa0b07f40a7b2

See more details on using hashes here.

File details

Details for the file os_py_lib_eb-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: os_py_lib_eb-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for os_py_lib_eb-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6b360364259b33ac56c18e1c8c57d4a4636a1a950c44784fc1caa56906bfcd59
MD5 f69bbc5b959ba9ac5e4788f367a5ebd8
BLAKE2b-256 c9a8ff04b344a11c2de77cc816bc5845c51bdeea96463501d40be4485e90bf33

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