Registry / observability / statsd-python

statsd-python

JSON →
library0.6.1pypypi✓ verified 83d ago

The `statsd-python` library (version 0.6.1) provides a simple Python client for sending metrics to a StatsD server via UDP. It supports incrementing counters, setting gauges, and recording timings. The library has a stable API and sees infrequent updates, making it a reliable choice for basic StatsD integration.

pip install statsd-python
INSTALL
IMPORT
SIG · STATSD-PYTHON
S
statsd-python
observabilitypythonv0.6.1
Install
1.6s avg
Import
41ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.6.1 · 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.910 runs
installs and imports cleanly · install 0.0s · import 0.042s · 17.9MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 1.6s · import 0.041s · 18MB
16MB installed
● package 16MB
Code
Verified usage

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

StatsdClient
from statsd import StatsdClient
import statsd; c = statsd.StatsClient(...)

This quickstart demonstrates how to initialize the `StatsClient` and send common metric types: counters (`incr`), gauges (`gauge`), and timings (`timing`). It also shows how to use a sample rate for counters.

import statsd import time import os # Configure StatsD client # Default StatsD host is usually 'localhost', port 8125 # Replace with your StatsD server's host and port if different statsd_host = os.environ.get('STATSD_HOST', 'localhost') statsd_port = int(os.environ.get('STATSD_PORT', '8125')) c = statsd.StatsClient(statsd_host, statsd_port) print(f"Sending metrics to StatsD server at {statsd_host}:{statsd_port}...") # Increment a counter c.incr('my_app.requests_total') print("Incremented 'my_app.requests_total'") # Set a gauge value c.gauge('my_app.active_users', 15) c.gauge('my_app.memory_usage_mb', 256.7) print("Set gauges for 'my_app.active_users' and 'my_app.memory_usage_mb'") # Record a timing (in milliseconds) start_time = time.time() time.sleep(0.05) # Simulate some work end_time = time.time() duration_ms = (end_time - start_time) * 1000 c.timing('my_app.process_duration_ms', duration_ms) print(f"Recorded timing for 'my_app.process_duration_ms': {duration_ms:.2f}ms") # Send with a sample rate (e.g., send only 50% of the time) c.incr('my_app.sampled_events', rate=0.5) print("Incremented 'my_app.sampled_events' with a 50% sample rate") print("Metrics sent. Check your StatsD server for reception.")
Debug
Known issues
gotchaMetrics are not visible in monitoring tools or appear inconsistent.
fix
StatsD uses UDP, a connectionless protocol. Packets are 'fire and forget' and provide no delivery guarantees. Network issues, firewalls, or an unavailable StatsD server will cause silent failures from the client's perspective. Ensure the StatsD server is running, reachable, and listening on the configured host/port. Check firewalls. Use `tcpdump` or Wireshark to verify UDP packets are leaving the client machine and arriving at the server.
affects: All versions
gotchaName collision with other 'statsd' or 'pystatsd' libraries.
fix
There are multiple Python libraries with similar names (`statsd`, `pystatsd`). This registry entry refers to `statsd-python` by lirsacc (`pip install statsd-python`). An older, now archived, library (often referred to as `pystatsd` or `statsd` by jsocol) had a different API. Verify you have installed `statsd-python` (`pip show statsd-python`) and are using its specific API (e.g., `import statsd` then `statsd.StatsClient`). If you encounter unexpected API errors, check for other `statsd` installations (`pip freeze | grep statsd`) and uninstall conflicting ones.
affects: All versions
Upgrade
Version history
0.6.1latest on PyPI · released Jun 13, 2023
Audit
Dependencies

No dependency data recorded yet.

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