Catalog PyPI
PACKAGE EXPLORERView in registry

aiobp

PyPI

Boilerplate for asyncio service

Versions collected1
Direct dependencies6From release 3.1.0
Last observed21 Oct, 11:41 UTC

README

Version 3.1.0 documentation

Asyncio Service Boilerplate

This module provides a foundation for building microservices using Python's asyncio library. Key features include:

  • A runner with graceful shutdown
  • A task reference management
  • A flexible configuration provider
  • A logger with colorized output
  • Optional OpenTelemetry logging and distributed tracing
  • Optional HTTP server with Swagger built on aiohttp
  • Optional NATS message bus connector

No dependencies are enforced by default, so you only install what you need. For basic usage, no additional Python modules are required. The table below summarizes which optional dependencies to install based on the features you want to use:

aiobp FeatureRequired Module(s)Extra
config (.conf or .json)msgspeclogging
config (.yaml)msgspec, pyyamllogging_yaml
OpenTelemetry loggingopentelemetry-sdk, opentelemetry-exporter-otlp-proto-grpclogging_otel
OpenTelemetry tracingopentelemetry-sdk, opentelemetry-exporter-otlp-proto-grpctracing_otel
HTTP server + Swaggeraiohttp, msgspecaiohttp
NATS message busnats-py, msgspecnats

Logs and traces share the same dependency set — install aiobp[otel] to get both:

pip install aiobp[otel]

Basic example

import asyncio

from aiobp import runner

async def main():
    try:
        await asyncio.sleep(60)
    except asyncio.CancelledError:
        print('Saving data...')

runner("Basic example", "0.0.0", main())

OpenTelemetry Logging

aiobp supports exporting logs to OpenTelemetry collectors (SigNoz, Jaeger, etc.).

Configuration

Add OTEL settings to your LoggingConfig:

[log]
level = DEBUG
console = INFO
filename = service.log
otel_endpoint = http://localhost:4317
otel_export_interval = 5
OptionDefaultDescription
levelDEBUGLog level for file and OTEL output
consoleINFOLog level for console output (under systemd it goes to syslog)
otel_endpointNoneOTLP gRPC endpoint (e.g. http://localhost:4317)
otel_export_interval5Export interval in seconds (0 = instant export)

Usage

from dataclasses import dataclass
from aiobp.logging import LoggingConfig, setup_logging, log

@dataclass
class Config:
    log: LoggingConfig = None

# ... load config ...

setup_logging("my-service-name", config.log)
log.info("This message goes to console, file, and OTEL collector")

Resource Attributes

To add custom resource attributes (like location, environment, etc.), set the standard OTEL environment variable before calling setup_logging:

import os

os.environ["OTEL_RESOURCE_ATTRIBUTES"] = "location=datacenter1,environment=production"
setup_logging("my-service-name", config.log)

Graceful Fallback

If otel_endpoint is configured but OpenTelemetry packages are not installed, a warning is logged and the application continues with console/file logging only.

OpenTelemetry Tracing

aiobp also supports exporting distributed traces to OpenTelemetry collectors. Call once at startup, then use traced(), current_span(), and start_span() anywhere in the codebase.

Setup

from aiobp import __version__
from aiobp.tracing import setup_tracing

setup_tracing("my-service", __version__, config.log.otel_endpoint)

Logging and tracing are independent — call either or both. The common pattern is to reuse the same OTLP endpoint:

from aiobp.logging import setup_logging
from aiobp.tracing import setup_tracing

setup_logging("my-service", config.log)                           # logs go to OTel if endpoint set
setup_tracing("my-service", __version__, config.log.otel_endpoint)  # traces share the endpoint

Usage

from aiobp.tracing import traced, current_span

async def do_work():
    result = await call_external_api()
    # Helper doesn't take the span as an argument — reach for the active one:
    current_span().set_attribute("result.id", result.id)
    return result

async with traced("operation.name", {"key": "value"}):
    await do_work()

traced accepts:

  • attrs — dict of span attributes.
  • context — an OTel Context for parent propagation.
  • traceparent — W3C traceparent string (alternative to context; the function calls extract() for you).
  • suppress — exception types to log-and-swallow inside the span (defaults to none).
  • errors_only=True — span is created lazily, only when an exception is raised. Useful for noisy event handlers where you only want to surface failures.

From any nested function call, current_span() returns the active span so you can attach attributes without threading the span through arguments.

Long-lived spans with start_span

traced() is a context manager — the span ends when the block exits. For spans that need to outlive a single function call (e.g. "caller is waiting for an agent" — open in one event handler, closed in another), use start_span() and call .end() yourself:

from aiobp.tracing import start_span

# Begin the wait — store the returned span somewhere
wait_span = start_span("queue.wait_for_agent", {"queue.id": 42}, traceparent=caller_traceparent)
self._wait_spans[caller.uuid] = wait_span

# Later, when the wait ends:
span = self._wait_spans.pop(caller.uuid, None)
if span:
    span.end()

start_span accepts the same attrs, context, and traceparent parameters as traced. The returned span is not installed as the current context — child spans elsewhere won't auto-nest under it. Use it for pure duration markers.

If tracing isn't configured, start_span returns a no-op span; calling .end() on it is harmless.

Graceful Fallback

If setup_tracing is never called, or the OpenTelemetry packages aren't installed, traced() becomes a no-op. Application code using traced() and current_span() works unchanged whether tracing is on or off.

Downloads & popularity

148downloads
1-day window · source-reported counts20 Oct 2026
19195.50
2026-07-23: 9 · observed 2026-10-21T15:31:16.0482749Z · period 2026-07-23–2026-07-232026-07-24: 73 · observed 2026-10-21T15:31:16.0482749Z · period 2026-07-24–2026-07-242026-07-26: 1 · observed 2026-10-21T15:31:16.0482749Z · period 2026-07-26–2026-07-262026-07-27: 13 · observed 2026-10-21T15:31:16.0482749Z · period 2026-07-27–2026-07-272026-07-28: 17 · observed 2026-10-21T15:31:16.0482749Z · period 2026-07-28–2026-07-282026-07-29: 4 · observed 2026-10-21T15:31:16.0482749Z · period 2026-07-29–2026-07-292026-07-30: 10 · observed 2026-10-21T15:31:16.0482749Z · period 2026-07-30–2026-07-302026-07-31: 8 · observed 2026-10-21T15:31:16.0482749Z · period 2026-07-31–2026-07-312026-08-01: 1 · observed 2026-10-21T15:31:16.0482749Z · period 2026-08-01–2026-08-012026-08-02: 1 · observed 2026-10-21T15:31:16.0482749Z · period 2026-08-02–2026-08-022026-08-03: 4 · observed 2026-10-21T15:31:16.0482749Z · period 2026-08-03–2026-08-032026-08-04: 15 · observed 2026-10-21T15:31:16.0482749Z · period 2026-08-04–2026-08-042026-08-05: 18 · observed 2026-10-21T15:31:16.0482749Z · period 2026-08-05–2026-08-052026-08-06: 29 · observed 2026-10-21T15:31:16.0482749Z · period 2026-08-06–2026-08-062026-08-07: 2 · observed 2026-10-21T15:31:16.0482749Z · period 2026-08-07–2026-08-072026-08-09: 8 · observed 2026-10-21T15:31:16.0482749Z · period 2026-08-09–2026-08-092026-08-10: 4 · observed 2026-10-21T15:31:16.0482749Z · period 2026-08-10–2026-08-102026-08-11: 42 · observed 2026-10-21T15:31:16.0482749Z · period 2026-08-11–2026-08-112026-08-12: 12 · observed 2026-10-21T15:31:16.0482749Z · period 2026-08-12–2026-08-122026-08-14: 12 · observed 2026-10-21T15:31:16.0482749Z · period 2026-08-14–2026-08-142026-08-15: 71 · observed 2026-10-21T15:31:16.0482749Z · period 2026-08-15–2026-08-152026-08-17: 10 · observed 2026-10-21T15:31:16.0482749Z · period 2026-08-17–2026-08-172026-08-18: 21 · observed 2026-10-21T15:31:16.0482749Z · period 2026-08-18–2026-08-182026-08-19: 18 · observed 2026-10-21T15:31:16.0482749Z · period 2026-08-19–2026-08-192026-08-20: 52 · observed 2026-10-21T15:31:16.0482749Z · period 2026-08-20–2026-08-202026-08-21: 22 · observed 2026-10-21T15:31:16.0482749Z · period 2026-08-21–2026-08-212026-08-22: 24 · observed 2026-10-21T15:31:16.0482749Z · period 2026-08-22–2026-08-222026-08-23: 75 · observed 2026-10-21T15:31:16.0482749Z · period 2026-08-23–2026-08-232026-08-24: 59 · observed 2026-10-21T15:31:16.0482749Z · period 2026-08-24–2026-08-242026-08-25: 33 · observed 2026-10-21T15:31:16.0482749Z · period 2026-08-25–2026-08-252026-08-28: 33 · observed 2026-10-21T15:31:16.0482749Z · period 2026-08-28–2026-08-282026-08-31: 5 · observed 2026-10-21T15:31:16.0482749Z · period 2026-08-31–2026-08-312026-09-01: 25 · observed 2026-10-21T15:31:16.0482749Z · period 2026-09-01–2026-09-012026-09-02: 22 · observed 2026-10-21T15:31:16.0482749Z · period 2026-09-02–2026-09-022026-09-03: 5 · observed 2026-10-21T15:31:16.0482749Z · period 2026-09-03–2026-09-032026-09-04: 4 · observed 2026-10-21T15:31:16.0482749Z · period 2026-09-04–2026-09-042026-09-06: 96 · observed 2026-10-21T15:31:16.0482749Z · period 2026-09-06–2026-09-062026-09-07: 34 · observed 2026-10-21T15:31:16.0482749Z · period 2026-09-07–2026-09-072026-09-08: 1 · observed 2026-10-21T15:31:16.0482749Z · period 2026-09-08–2026-09-082026-09-09: 6 · observed 2026-10-21T15:31:16.0482749Z · period 2026-09-09–2026-09-092026-09-10: 18 · observed 2026-10-21T15:31:16.0482749Z · period 2026-09-10–2026-09-102026-09-11: 39 · observed 2026-10-21T15:31:16.0482749Z · period 2026-09-11–2026-09-112026-09-12: 1 · observed 2026-10-21T15:31:16.0482749Z · period 2026-09-12–2026-09-122026-09-13: 8 · observed 2026-10-21T15:31:16.0482749Z · period 2026-09-13–2026-09-132026-09-14: 101 · observed 2026-10-21T15:31:16.0482749Z · period 2026-09-14–2026-09-142026-09-15: 8 · observed 2026-10-21T15:31:16.0482749Z · period 2026-09-15–2026-09-152026-09-16: 124 · observed 2026-10-21T15:31:16.0482749Z · period 2026-09-16–2026-09-162026-09-17: 4 · observed 2026-10-21T15:31:16.0482749Z · period 2026-09-17–2026-09-172026-09-18: 38 · observed 2026-10-21T15:31:16.0482749Z · period 2026-09-18–2026-09-182026-09-19: 7 · observed 2026-10-21T15:31:16.0482749Z · period 2026-09-19–2026-09-192026-09-20: 29 · observed 2026-10-21T15:31:16.0482749Z · period 2026-09-20–2026-09-202026-09-21: 18 · observed 2026-10-21T15:31:16.0482749Z · period 2026-09-21–2026-09-212026-09-22: 127 · observed 2026-10-21T15:31:16.0482749Z · period 2026-09-22–2026-09-222026-09-23: 9 · observed 2026-10-21T15:31:16.0482749Z · period 2026-09-23–2026-09-232026-09-24: 24 · observed 2026-10-21T15:31:16.0482749Z · period 2026-09-24–2026-09-242026-09-25: 5 · observed 2026-10-21T15:31:16.0482749Z · period 2026-09-25–2026-09-252026-09-26: 93 · observed 2026-10-21T15:31:16.0482749Z · period 2026-09-26–2026-09-262026-09-27: 5 · observed 2026-10-21T15:31:16.0482749Z · period 2026-09-27–2026-09-272026-09-28: 3 · observed 2026-10-21T15:31:16.0482749Z · period 2026-09-28–2026-09-282026-09-29: 10 · observed 2026-10-21T15:31:16.0482749Z · period 2026-09-29–2026-09-292026-09-30: 3 · observed 2026-10-21T15:31:16.0482749Z · period 2026-09-30–2026-09-302026-10-01: 4 · observed 2026-10-21T15:31:16.0482749Z · period 2026-10-01–2026-10-012026-10-02: 7 · observed 2026-10-21T15:31:16.0482749Z · period 2026-10-02–2026-10-022026-10-03: 2 · observed 2026-10-21T15:31:16.0482749Z · period 2026-10-03–2026-10-032026-10-04: 7 · observed 2026-10-21T15:31:16.0482749Z · period 2026-10-04–2026-10-042026-10-05: 19 · observed 2026-10-21T15:31:16.0482749Z · period 2026-10-05–2026-10-052026-10-06: 8 · observed 2026-10-21T15:31:16.0482749Z · period 2026-10-06–2026-10-062026-10-07: 5 · observed 2026-10-21T15:31:16.0482749Z · period 2026-10-07–2026-10-072026-10-08: 14 · observed 2026-10-21T15:31:16.0482749Z · period 2026-10-08–2026-10-082026-10-09: 1 · observed 2026-10-21T15:31:16.0482749Z · period 2026-10-09–2026-10-092026-10-10: 34 · observed 2026-10-21T15:31:16.0482749Z · period 2026-10-10–2026-10-102026-10-11: 13 · observed 2026-10-21T15:31:16.0482749Z · period 2026-10-11–2026-10-112026-10-12: 4 · observed 2026-10-21T15:31:16.0482749Z · period 2026-10-12–2026-10-122026-10-13: 191 · observed 2026-10-21T15:31:16.0482749Z · period 2026-10-13–2026-10-132026-10-14: 35 · observed 2026-10-21T15:31:16.0482749Z · period 2026-10-14–2026-10-142026-10-15: 13 · observed 2026-10-21T15:31:16.0482749Z · period 2026-10-15–2026-10-152026-10-16: 14 · observed 2026-10-21T15:31:16.0482749Z · period 2026-10-16–2026-10-162026-10-17: 19 · observed 2026-10-21T15:31:16.0482749Z · period 2026-10-17–2026-10-172026-10-18: 8 · observed 2026-10-21T15:31:16.0482749Z · period 2026-10-18–2026-10-182026-10-19: 177 · observed 2026-10-21T15:31:16.0482749Z · period 2026-10-19–2026-10-192026-10-20: 148 · observed 2026-10-21T15:31:16.0482749Z · period 2026-10-20–2026-10-20
23 Jul20 Oct

pypistats · 81 observations shown. Missing days are unknown. Source category: overall: without mirrors.

View observed values
Date / source periodValueObserved at
2026-10-20 – 2026-10-201482026-10-21T15:31:16.0482749Z
2026-10-19 – 2026-10-191772026-10-21T15:31:16.0482749Z
2026-10-18 – 2026-10-1882026-10-21T15:31:16.0482749Z
2026-10-17 – 2026-10-17192026-10-21T15:31:16.0482749Z
2026-10-16 – 2026-10-16142026-10-21T15:31:16.0482749Z
2026-10-15 – 2026-10-15132026-10-21T15:31:16.0482749Z
2026-10-14 – 2026-10-14352026-10-21T15:31:16.0482749Z
2026-10-13 – 2026-10-131912026-10-21T15:31:16.0482749Z
2026-10-12 – 2026-10-1242026-10-21T15:31:16.0482749Z
2026-10-11 – 2026-10-11132026-10-21T15:31:16.0482749Z
2026-10-10 – 2026-10-10342026-10-21T15:31:16.0482749Z
2026-10-09 – 2026-10-0912026-10-21T15:31:16.0482749Z
2026-10-08 – 2026-10-08142026-10-21T15:31:16.0482749Z
2026-10-07 – 2026-10-0752026-10-21T15:31:16.0482749Z
2026-10-06 – 2026-10-0682026-10-21T15:31:16.0482749Z
2026-10-05 – 2026-10-05192026-10-21T15:31:16.0482749Z
2026-10-04 – 2026-10-0472026-10-21T15:31:16.0482749Z
2026-10-03 – 2026-10-0322026-10-21T15:31:16.0482749Z
2026-10-02 – 2026-10-0272026-10-21T15:31:16.0482749Z
2026-10-01 – 2026-10-0142026-10-21T15:31:16.0482749Z
2026-09-30 – 2026-09-3032026-10-21T15:31:16.0482749Z
2026-09-29 – 2026-09-29102026-10-21T15:31:16.0482749Z
2026-09-28 – 2026-09-2832026-10-21T15:31:16.0482749Z
2026-09-27 – 2026-09-2752026-10-21T15:31:16.0482749Z
2026-09-26 – 2026-09-26932026-10-21T15:31:16.0482749Z
2026-09-25 – 2026-09-2552026-10-21T15:31:16.0482749Z
2026-09-24 – 2026-09-24242026-10-21T15:31:16.0482749Z
2026-09-23 – 2026-09-2392026-10-21T15:31:16.0482749Z
2026-09-22 – 2026-09-221272026-10-21T15:31:16.0482749Z
2026-09-21 – 2026-09-21182026-10-21T15:31:16.0482749Z
2026-09-20 – 2026-09-20292026-10-21T15:31:16.0482749Z
2026-09-19 – 2026-09-1972026-10-21T15:31:16.0482749Z
2026-09-18 – 2026-09-18382026-10-21T15:31:16.0482749Z
2026-09-17 – 2026-09-1742026-10-21T15:31:16.0482749Z
2026-09-16 – 2026-09-161242026-10-21T15:31:16.0482749Z
2026-09-15 – 2026-09-1582026-10-21T15:31:16.0482749Z
2026-09-14 – 2026-09-141012026-10-21T15:31:16.0482749Z
2026-09-13 – 2026-09-1382026-10-21T15:31:16.0482749Z
2026-09-12 – 2026-09-1212026-10-21T15:31:16.0482749Z
2026-09-11 – 2026-09-11392026-10-21T15:31:16.0482749Z
2026-09-10 – 2026-09-10182026-10-21T15:31:16.0482749Z
2026-09-09 – 2026-09-0962026-10-21T15:31:16.0482749Z
2026-09-08 – 2026-09-0812026-10-21T15:31:16.0482749Z
2026-09-07 – 2026-09-07342026-10-21T15:31:16.0482749Z
2026-09-06 – 2026-09-06962026-10-21T15:31:16.0482749Z
2026-09-04 – 2026-09-0442026-10-21T15:31:16.0482749Z
2026-09-03 – 2026-09-0352026-10-21T15:31:16.0482749Z
2026-09-02 – 2026-09-02222026-10-21T15:31:16.0482749Z
2026-09-01 – 2026-09-01252026-10-21T15:31:16.0482749Z
2026-08-31 – 2026-08-3152026-10-21T15:31:16.0482749Z
2026-08-28 – 2026-08-28332026-10-21T15:31:16.0482749Z
2026-08-25 – 2026-08-25332026-10-21T15:31:16.0482749Z
2026-08-24 – 2026-08-24592026-10-21T15:31:16.0482749Z
2026-08-23 – 2026-08-23752026-10-21T15:31:16.0482749Z
2026-08-22 – 2026-08-22242026-10-21T15:31:16.0482749Z
2026-08-21 – 2026-08-21222026-10-21T15:31:16.0482749Z
2026-08-20 – 2026-08-20522026-10-21T15:31:16.0482749Z
2026-08-19 – 2026-08-19182026-10-21T15:31:16.0482749Z
2026-08-18 – 2026-08-18212026-10-21T15:31:16.0482749Z
2026-08-17 – 2026-08-17102026-10-21T15:31:16.0482749Z
2026-08-15 – 2026-08-15712026-10-21T15:31:16.0482749Z
2026-08-14 – 2026-08-14122026-10-21T15:31:16.0482749Z
2026-08-12 – 2026-08-12122026-10-21T15:31:16.0482749Z
2026-08-11 – 2026-08-11422026-10-21T15:31:16.0482749Z
2026-08-10 – 2026-08-1042026-10-21T15:31:16.0482749Z
2026-08-09 – 2026-08-0982026-10-21T15:31:16.0482749Z
2026-08-07 – 2026-08-0722026-10-21T15:31:16.0482749Z
2026-08-06 – 2026-08-06292026-10-21T15:31:16.0482749Z
2026-08-05 – 2026-08-05182026-10-21T15:31:16.0482749Z
2026-08-04 – 2026-08-04152026-10-21T15:31:16.0482749Z
2026-08-03 – 2026-08-0342026-10-21T15:31:16.0482749Z
2026-08-02 – 2026-08-0212026-10-21T15:31:16.0482749Z
2026-08-01 – 2026-08-0112026-10-21T15:31:16.0482749Z
2026-07-31 – 2026-07-3182026-10-21T15:31:16.0482749Z
2026-07-30 – 2026-07-30102026-10-21T15:31:16.0482749Z
2026-07-29 – 2026-07-2942026-10-21T15:31:16.0482749Z
2026-07-28 – 2026-07-28172026-10-21T15:31:16.0482749Z
2026-07-27 – 2026-07-27132026-10-21T15:31:16.0482749Z
2026-07-26 – 2026-07-2612026-10-21T15:31:16.0482749Z
2026-07-24 – 2026-07-24732026-10-21T15:31:16.0482749Z
2026-07-23 – 2026-07-2392026-10-21T15:31:16.0482749Z

Versions 1

Collected releases
VersionPublishedDirect dependenciesOpen version
3.1.020 Oct 20266

Package advisories

0
No matching advisories collected

This describes our collected data; it is not a security assessment.

Metadata history

Meaningful changes
Current collected state Current

Observed since 21 Oct, 11:41 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package:2ab70c0e87fece411de40d24578df20577ddfd0af349f3a7842c6d700a344013