Registry / observability / python-statsd

python-statsd

JSON →
library2.1.0pypypi✓ verified 24d ago

python-statsd is a Python client for the StatsD daemon, a front-end/proxy for Graphite's stats collection and graphing server. While the user-provided slug is 'python-statsd' (version 2.1.0), this PyPI project typically redirects to 'statsd' (currently 4.0.1). This entry reflects the features and usage of the actively maintained 'statsd' package on PyPI, which is the direct successor and most commonly used client. It allows applications to send various metrics like counters, timers, and gauges over UDP (or TCP) for aggregation and monitoring. The library generally follows a stable release cadence for minor bug fixes and feature enhancements.

pip install statsd
INSTALL
IMPORT
SIG · PYTHON-STATSD
P
python-statsd
observabilitypythonv2.1.0
Install
1.5s avg
Import
40ms
Disk
101MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v? · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.044s · 65.7MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.5s · import 0.036s · 137MB
101MB installed
● package 101MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

StatsClient
from statsd import StatsClient

This quickstart demonstrates how to initialize a StatsD client and send common metric types: counters, timers, and gauges. It uses environment variables for host and port for easy configuration, defaulting to localhost:8125. A prefix is added to all metrics for better organization.

import statsd import os # Configure StatsD client, typically pointing to a local StatsD agent # Default host is 'localhost', default port is 8125 # You can override with environment variables or direct arguments statsd_host = os.environ.get('STATSD_HOST', 'localhost') statsd_port = int(os.environ.get('STATSD_PORT', 8125)) c = statsd.StatsClient(host=statsd_host, port=statsd_port, prefix='my_app') # Increment a counter c.incr('page_views') c.incr('successful_requests', 5) # Record a timing (in milliseconds) import time start_time = time.time() time.sleep(0.05) # Simulate work duration_ms = (time.time() - start_time) * 1000 c.timing('api_response_time', duration_ms) # Set a gauge value c.gauge('current_users', 150) print(f"Sent metrics to StatsD at {statsd_host}:{statsd_port}") print("Check your StatsD server/Graphite for 'my_app.page_views', 'my_app.successful_requests', 'my_app.api_response_time', 'my_app.current_users'")
Debug
Known issues
breakingThe PyPI package `python-statsd` has effectively been replaced by `statsd` (maintained by `jsocol/pystatsd`). While `WoLpH/python-statsd` GitHub repo lists version 2.1.0, its own documentation links point to the `statsd` package (currently 4.0.1). Installing `python-statsd` via pip today will install the `statsd` package.
fix
Use `pip install statsd`. Ensure your code uses `from statsd import StatsClient`. If you specifically need features from older `python-statsd` (2.x), verify its API is compatible or find an archived version.
affects: <4.0.0 (for old `python-statsd`)
gotchaThis library (`statsd` on PyPI) explicitly does not support tagged metrics (e.g., `metric:value|#tag1:foo,tag2:bar`) used by systems like Datadog, Telegraf, or Prometheus StatsD exporters. Attempting to send tags will result in data loss or incorrect metric names.
fix
If you require tagged metrics, consider alternative Python StatsD clients like `dogstatsd-python` or `statsd-exporter`, or adjust your metric naming strategy to encode tags into the metric name itself (e.g., `my_metric.foo.bar`).
affects: All versions of `statsd` (PyPI package)
gotchaStatsD primarily uses UDP for metric transmission, which is a 'fire-and-forget' protocol. While highly performant, it does not guarantee delivery. Packets can be silently dropped by the network or the StatsD server under heavy load or network issues.
fix
For critical metrics where delivery is paramount, consider using a StatsD server and client that support TCP (if available in your setup) or explore other monitoring solutions designed for guaranteed delivery. For standard use, acknowledge the UDP trade-off and monitor your StatsD server for dropped packets.
affects: All versions
gotchaSeveral Python libraries exist on PyPI with 'statsd' in their name (e.g., `statsd`, `statsd-client`, `statsd-exporter`, `statsd-tags`). This can lead to confusion and accidentally installing a different client with a non-compatible API or missing features.
fix
Always explicitly `pip install statsd` (for this library). Verify your `import statsd` correctly brings in the `StatsClient` class, and consult the documentation for the specific client you intend to use.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'python_statsd'
The user is attempting to import a package named `python_statsd`, but the correct and actively maintained package on PyPI is named `statsd`.
fix
Install the correct package using `pip install statsd` and update the import statement in your code to `import statsd`.
AttributeError: 'StatsClient' object has no attribute 'count'
The `statsd` library uses `incr` and `decr` methods for incrementing and decrementing counters, not a method named `count` or `counter`.
fix
Use `client.incr('metric_name')` or `client.decr('metric_name')` to update counters.
TypeError: __init__() missing 1 required positional argument: 'host'
The `StatsClient` class constructor requires at least the StatsD server's hostname as its first argument.
fix
Initialize the `StatsClient` with the target host and optionally the port, for example: `c = statsd.StatsClient('localhost', 8125)`.
Upgrade
Version history
2.1.0latest on PyPI · released Sep 5, 2017
Audit
Dependencies

No dependency data recorded yet.

Agent activity
22 hits · last 30 days
node
16
OpenAI (training)
2
Amazon
1
Resources
python-statsd — pip install python-statsd · libregistry