grapicli
A command-line tool for querying the Graylog REST API, built with Typer and Rich.
Features
- 🔍 Search logs by source host, message content, or any combination
- 🕐 Flexible time ranges — relative (last N minutes) or absolute (
--since/--until) - 📋 Configurable result limits with
--limit - 🔑 Token-based authentication loaded automatically from a
.envfile - 🖥️ Rich terminal output — results displayed in a colour-coded table
Installation
grapicli requires Python 3.14 or newer. The recommended way to install is directly from PyPI into a dedicated virtual environment.
1. Create a virtual environment
python3.14 -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
Tip: If you manage multiple Python versions, use pyenv to install 3.14 first:
pyenv install 3.14 pyenv local 3.14 python -m venv .venv && source .venv/bin/activate
2. Install from PyPI
pip install grapicli
Verify the installation:
grapicli --help
Configuration
Create a .env file in your working directory with your Graylog credentials:
export GRAYLOG_URL=https://your-graylog-server
export GRAYLOG_TOKEN=your_api_token_here
Note: Never commit your
.envfile to version control.
Finding your API token
- Log in to the Graylog web interface.
- Go to System → Users and Teams → Edit Profile → API Tokens.
- Create a new token and copy the value into your
.envfile.
Usage
grapicli search [OPTIONS]
Options
| Flag | Short | Type | Default | Description |
|---|---|---|---|---|
--source |
-s |
TEXT | — | Filter by source host or identifier |
--message |
-m |
TEXT | — | Filter by message text (Lucene substring match) |
--limit |
-n |
INT | 30 |
Maximum number of messages to return |
--last |
-l |
INT | 15 |
Return messages from the last N minutes |
--since |
-S |
TEXT | — | Start of an absolute time range |
--until |
-U |
TEXT | — | End of an absolute time range (defaults to now) |
Time range
Relative (default) — returns messages from the last 15 minutes:
grapicli search
grapicli search --last 60 # last hour
Absolute — --since and/or --until switch to an exact range. All times are UTC.
Accepted formats: YYYY-MM-DD HH:MM:SS · YYYY-MM-DDTHH:MM:SS · YYYY-MM-DD HH:MM · YYYY-MM-DD
grapicli search --since "2026-04-17 08:00:00" --until "2026-04-17 09:00:00"
Examples
# Default: last 15 minutes, up to 30 messages
grapicli search
# Filter by source host
grapicli search --source myserver
# Filter by message text and increase result count
grapicli search --message "error" --limit 100
# Last hour
grapicli search --last 60
# Absolute range
grapicli search --since "2026-04-17 08:00:00" --until "2026-04-17 09:00:00"
# Combine source, message filter, and time range
grapicli search --source myserver --message "timeout" --since "2026-04-17 12:00:00"
Output
Query: source:"myserver" Matches: 4821 Showing: 30/30
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Timestamp ┃ Source ┃ Message ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ 2026-04-17T10:00:01.000Z │ myserver │ Service started successfully │
│ 2026-04-17T10:00:02.000Z │ myserver │ Connected to database │
└──────────────────────────┴────────────┴────────────────────────────────────┘
Development
Clone the repository and install with dev dependencies using Poetry:
git clone https://github.com/mmackenna/grapicli.git
cd grapicli
poetry install --extras dev
Running tests
poetry run pytest
Coverage report is written to htmlcov/.
Building docs locally
poetry run mkdocs serve
License
Metadata
Release files for grapicli 0.10.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| grapicli-0.10.0.tar.gz | 6.4 kB | Without provenance | Details for grapicli-0.10.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| grapicli-0.10.0-py3-none-any.whl | Python 3 | none | any | Details for grapicli-0.10.0-py3-none-any.whl |
Total release size: 14.2 kB
Release files / grapicli-0.10.0.tar.gz
| Download URL | grapicli-0.10.0.tar.gz |
|---|---|
| Size | 6.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c84372a25e0e1df7d87a06d96dc4a0911d86e0e83b1a97d4bb7e1cab889515f9
|
|
BLAKE2b-256 checksum How to use checksums |
c9ab7817246c1a697dc55c44ac4d91fda5b3a6abc58b3b568504fcc769a2fea8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.3.4 CPython/3.14.4 Linux/5.14.0-611.47.1.el9_7.x86_64
|
Release files / grapicli-0.10.0-py3-none-any.whl
| Download URL | grapicli-0.10.0-py3-none-any.whl |
|---|---|
| Size | 7.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3b695081a20ede3ac372bebaf5afe95baf0cdddfad6ba051613cae07056fa640
|
|
BLAKE2b-256 checksum How to use checksums |
7c5ef21e0df032f864577b4d0d323966f4f1cb2581272bcaa70718c937c4a500
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.3.4 CPython/3.14.4 Linux/5.14.0-611.47.1.el9_7.x86_64
|
Security for grapicli 0.10.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.