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
- Upgrade the application to Python 3.11 or newer.
- Retain existing
monitoring_adapter.startup(...),send(), andserve()calls. - 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
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 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e4752033de59a14fc7f6f2447b1631c542eade1e39afd7e0dd78279883bcac48
|
|
| MD5 |
2d8dbd24ed5283b417f4b4409f712cac
|
|
| BLAKE2b-256 |
eeb62a87b2528bff15c73c9a1b106a46bc0ebf9c25534385ffaca018eb287aff
|
Provenance
The following attestation bundles were made for prometheus_pusher-1.0.0.tar.gz:
Publisher:
publish.yml on bigbag/prometheus-pusher
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
prometheus_pusher-1.0.0.tar.gz -
Subject digest:
e4752033de59a14fc7f6f2447b1631c542eade1e39afd7e0dd78279883bcac48 - Sigstore transparency entry: 2205863792
- Sigstore integration time:
-
Permalink:
bigbag/prometheus-pusher@a3e926aac984e1323dce19c69761e932b934ccbf -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/bigbag
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a3e926aac984e1323dce19c69761e932b934ccbf -
Trigger Event:
push
-
Statement type:
File details
Details for the file prometheus_pusher-1.0.0-py3-none-any.whl.
File metadata
- Download URL: prometheus_pusher-1.0.0-py3-none-any.whl
- Upload date:
- Size: 9.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9840c9dae2b97f15a37d18c08b55e77d64b14831139472644ec134361c619ee0
|
|
| MD5 |
953576b87b3e5505bc3c063d9133180b
|
|
| BLAKE2b-256 |
11e895cd8af48524dc08c8a3ce9bf520cc42f59bab8e542c266d0679a6017ec7
|
Provenance
The following attestation bundles were made for prometheus_pusher-1.0.0-py3-none-any.whl:
Publisher:
publish.yml on bigbag/prometheus-pusher
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
prometheus_pusher-1.0.0-py3-none-any.whl -
Subject digest:
9840c9dae2b97f15a37d18c08b55e77d64b14831139472644ec134361c619ee0 - Sigstore transparency entry: 2205863900
- Sigstore integration time:
-
Permalink:
bigbag/prometheus-pusher@a3e926aac984e1323dce19c69761e932b934ccbf -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/bigbag
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a3e926aac984e1323dce19c69761e932b934ccbf -
Trigger Event:
push
-
Statement type: