Python SDK
Install the Logdash Python SDK, send your first log and your first metric.
Install the package, paste your API key and the first log lands in the dashboard within a second. Everything below is copied from the Python SDK README.
Install
pip install logdash Initialise
Create a project in Logdash, copy its API key and keep it in an environment variable. The key identifies the project the data lands in.
import os
from logdash import create_logdash
logdash = create_logdash({
"api_key": os.environ["LOGDASH_API_KEY"],
}) Send a log
import os
from logdash import create_logdash
logdash = create_logdash({"api_key": os.environ["LOGDASH_API_KEY"]})
logger = logdash.logger
logger.info("Application started successfully")
logger.error("An unexpected error occurred")
logger.warn("Low disk space warning") Send a metric
Metrics are named numbers. Set one to an absolute value or mutate it by a delta, and Logdash charts the history.
import os
from logdash import create_logdash
logdash = create_logdash({"api_key": os.environ["LOGDASH_API_KEY"]})
metrics = logdash.metrics
# to set absolute value
metrics.set("users", 0)
# to modify existing metric
metrics.mutate("users", 1) Works with
- FastAPI
- Django
- Flask
- Celery
FAQ
Is the API key required?
No. Without one the logger still writes to your console. Metrics are hosted remotely only, so `metrics.set` and `metrics.mutate` need a key to show up anywhere.
Where do the logger and metrics objects come from?
`create_logdash` returns a client. Read `logdash.logger` for logging and `logdash.metrics` for counters and gauges.
Is there a Django or Flask integration?
No framework binding ships with the SDK. `create_logdash` is the whole surface, so build one client at startup and import it where you need it.