Send a custom metric from Python
Two functions — a counter and a gauge — over plain HTTPS. EzStat creates the stat on the first call, draws the chart, and exports CSV or JSON whenever you ask. No agent, no exporter, no statsd client to install.
Free: 10 stats, 300,000 datapoints a month, no card, open to the first 250 accounts. Paid plans are $19, $49 or $99 a month, and every paid plan tracks 10,000 stats. Prices are flat and monthly, in USD, + tax where applicable. /pricing is the source of truth. Alerts on paid plans, by webhook or Slack, checked periodically — not instant.
Before you start
Create an account and copy your API key (shown once) into EZSTAT_API_KEY. The key works at once, with one stat and 500 datapoints a day until you confirm your email address; confirm within 7 days to keep sending. The examples below write more than one stat, so confirm before you run them all. The free plan allows 10 stats. A counter and a duration for one job fit easily.
Record a counter or a gauge
import os
from urllib.parse import quote
import requests
API = "https://api.ezstat.dev/api/v1/stats"
KEY = os.environ["EZSTAT_API_KEY"] # never hard-code the key
def _post(stat: str, kind: str, body: dict) -> None:
r = requests.post(
f"{API}/{quote(stat, safe='')}/{kind}",
headers={"Authorization": f"Bearer {KEY}", "User-Agent": "my-app/1.0"},
json=body,
timeout=5,
)
r.raise_for_status() # v1 routes return real 4xx/5xx codes on rejection
def track_count(stat: str, count: int = 1) -> None:
_post(stat, "count", {"count": count})
def track_value(stat: str, value: float) -> None:
_post(stat, "value", {"value": value})
if __name__ == "__main__":
track_count("signups")
track_value("checkout_ms", 142)A counter is a running total; a gauge is a measurement at a moment in time. One stat is one or the other, never both, so stay with /count or /value for each stat.
Time a block of code
import time
from contextlib import contextmanager
import requests
# track_value() is the helper defined above.
@contextmanager
def timed(stat: str):
"""Record how long a block took, in seconds. A failed metric call never breaks the job."""
start = time.monotonic()
try:
yield
finally:
try:
track_value(stat, round(time.monotonic() - start, 3))
except requests.RequestException:
pass
with timed("nightly_import_seconds"):
run_import() # your real workThe duration is recorded in a finally block, and a failed metric call is swallowed — so a metrics outage never fails the job it is measuring.
What a failure means
A rejection raises HTTPError: 401 bad key, 403 plan limit on stats or datapoints, 429 rate limited (or the starting limit before you confirm your email), 400 malformed input. The point was not stored. A timeout or connection error means the outcome is unknown — the point may already be in. Retry only with the same explicit timestamp and ikey on every attempt:
# Retry-safe: the same timestamp + ikey on every attempt for one logical event.
import requests
requests.post(
"https://api.ezstat.dev/api/v1/stats/orders/count",
headers={"Authorization": f"Bearer {KEY}", "User-Agent": "my-app/1.0"},
json={"count": 1, "timestamp": "2026-12-03T09:15:00Z", "ikey": "order-9831"},
timeout=5,
).raise_for_status()De-duplication keys on stat + timestamp + ikey; an ikey without a timestamp does not protect you, because each attempt is then stamped on arrival. Rules: /docs#replay-semantics.
Standard library only
import json
import os
import urllib.request
req = urllib.request.Request(
"https://api.ezstat.dev/api/v1/stats/signups/count",
data=json.dumps({"count": 1}).encode(),
headers={
"Authorization": f"Bearer {os.environ['EZSTAT_API_KEY']}",
"Content-Type": "application/json",
"User-Agent": "my-app/1.0", # name your client; do not leave urllib's default
},
method="POST",
)
with urllib.request.urlopen(req, timeout=5) as resp:
print(resp.status, resp.read().decode())The User-Agent line is not decoration. On the ezstat.dev host, Python's default Python-urllib/* agent is blocked at the edge with a 403 and no EzStat error body, so it looks like an outage. These examples call api.ezstat.dev, where a default agent reached us when we checked on 1 Dec 2026 — naming your client costs nothing either way. Details in the docs.
Price and limits
Free: 10 stats, 300,000 datapoints a month, no card, open to the first 250 accounts. Paid plans are $19, $49 or $99 a month and every paid plan tracks 10,000 stats; the history you can see and export is 30 days on Free and Indie, 1 year on Pro, 3 years on Scale. A stat is one named metric, so budget two or three per job. See the full table.
Other languages
The same two calls in Node.js, Go and curl. From a scheduled job, see /cron-metrics; from an existing StatHat client, /migrate/stathat. Weighing this against a full observability suite? /datadog-alternative compares the two honestly.
Questions
How do I send a custom metric from Python?
POST JSON with requests: requests.post("https://api.ezstat.dev/api/v1/stats/signups/count", headers={"Authorization": f"Bearer {key}"}, json={"count": 1}, timeout=5), then call raise_for_status(). Use /count for a counter and /value with {"value": 142} for a gauge. The stat is created on the first request and charted automatically. Read the key from an environment variable, not from your code.
How do I record how long a function takes in Python?
Wrap it in a context manager that reads time.monotonic() before and after, then POST the elapsed seconds as a value to a stat such as nightly_import_seconds. Catch the request error so a metrics outage never fails the job. EzStat charts the series, and the history you can see and export is 30 days on Free and Indie, 1 year on Pro, 3 years on Scale.
What happens if my Python metrics call times out?
A timeout leaves the outcome unknown: the point may have been stored after your client gave up. A rejection raises HTTPError, which means it was not stored. To retry without double-counting, send the same explicit timestamp and idempotency key (ikey) on every attempt; without a fixed timestamp, each attempt is stored again.
Can I send a metric without installing requests?
Yes. urllib.request from the standard library works. Set your own User-Agent header anyway: on the ezstat.dev host Python's default Python-urllib/* agent is blocked at the edge with a 403 that carries no EzStat error body. The examples here call api.ezstat.dev, and naming your client costs nothing.
How many metrics can I send on the free plan?
A stat is one named metric. Free: 10 stats, 300,000 datapoints a month, no card, open to the first 250 accounts. Every paid plan allows 10,000 stats and more datapoints a month; Pro and Scale add longer history.