Skip to main content

prometheus-pusher

A lifecycle-safe helper for pushing application metrics to a Prometheus Pushgateway.

Requirements

Python 3.11 or newer. CI validates Python 3.11, 3.12, 3.13, and 3.14.

Install

uv add prometheus-pusher
pip install prometheus-pusher

Usage

from prometheus_client import CollectorRegistry, Counter

from prometheus_pusher import monitoring_adapter

registry = CollectorRegistry()
requests = Counter("demo_requests_total", "Number of demo requests", registry=registry)

monitoring_adapter.startup(
    gateway="http://127.0.0.1:9091",
    job_name="demo",
    registry=registry,
    is_enabled=True,
)

try:
    requests.inc()
    monitoring_adapter.send()  # Push immediately.
    monitoring_adapter.serve(worker_timeout=10)  # Then push every 10 seconds.
finally:
    monitoring_adapter.shutdown()

startup() configures the adapter. send() performs one push. serve() starts one daemon worker and is idempotent while that worker is alive. shutdown() signals and joins the adapter-owned worker; call it during application shutdown. A disabled adapter (is_enabled=False) remains a no-op.

Pass user and password for HTTP Basic authentication. Set ssl_verify=True for HTTPS endpoints with certificate verification; ssl_verify=False disables certificate validation and should be used only for trusted development environments. Push and network failures are logged and do not interrupt application execution.

Migrating from 0.1.0

  1. Upgrade the application to Python 3.11 or newer.
  2. Retain existing monitoring_adapter.startup(...), send(), and serve() calls.
  3. Add monitoring_adapter.shutdown() to the application's graceful-shutdown path.

Version 1.0.0 replaces the global, never-stopped worker with lifecycle owned by each MonitoringAdapter instance.

Development

uv sync --all-groups
uv run ruff format --check src tests examples
uv run ruff check src tests examples
uv run mypy src
uv run pytest --cov=prometheus_pusher
uv build

License and security

Distributed under the Apache License 2.0. See the security policy to report vulnerabilities.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

prometheus_pusher-1.0.0.tar.gz (43.5 kB view details)

Uploaded Source

Built Distribution

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

prometheus_pusher-1.0.0-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file prometheus_pusher-1.0.0.tar.gz.

File metadata

  • Download URL: prometheus_pusher-1.0.0.tar.gz
  • Upload date:
  • Size: 43.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for prometheus_pusher-1.0.0.tar.gz
Algorithm Hash digest
SHA256 e4752033de59a14fc7f6f2447b1631c542eade1e39afd7e0dd78279883bcac48
MD5 2d8dbd24ed5283b417f4b4409f712cac
BLAKE2b-256 eeb62a87b2528bff15c73c9a1b106a46bc0ebf9c25534385ffaca018eb287aff

See more details on using hashes here.

Provenance

The following attestation bundles were made for prometheus_pusher-1.0.0.tar.gz:

Publisher: publish.yml on bigbag/prometheus-pusher

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file prometheus_pusher-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for prometheus_pusher-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9840c9dae2b97f15a37d18c08b55e77d64b14831139472644ec134361c619ee0
MD5 953576b87b3e5505bc3c063d9133180b
BLAKE2b-256 11e895cd8af48524dc08c8a3ce9bf520cc42f59bab8e542c266d0679a6017ec7

See more details on using hashes here.

Provenance

The following attestation bundles were made for prometheus_pusher-1.0.0-py3-none-any.whl:

Publisher: publish.yml on bigbag/prometheus-pusher

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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