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.2.0.tar.gz (8.4 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.2.0-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: os_py_lib_eb-1.2.0.tar.gz
  • Upload date:
  • Size: 8.4 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.2.0.tar.gz
Algorithm Hash digest
SHA256 7f356d5213d524e1a8a8d46a76003420c0bdbbf9ab437b94ce1e3df1e163eda6
MD5 773760c80e4c189468cb8f017ee08700
BLAKE2b-256 02df01abb9d74708296aff81bd43f05e75924c9601cb21172b3b91430e7b1e68

See more details on using hashes here.

File details

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

File metadata

  • Download URL: os_py_lib_eb-1.2.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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9cc0ac62f1c368087a872e2eb31e71697102fb6a212c2672bd87f69739fafd1d
MD5 8a0e2c61621ac6fa451fe17a87637fce
BLAKE2b-256 c0dcfd0a2cb4d2d5b3d8d42b71e1a421ba887d849b7155ce33dc2a10bc00b98c

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