A command-line tool for querying the Graylog API with rich terminal output
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file grapicli-0.5.0.tar.gz.
File metadata
- Download URL: grapicli-0.5.0.tar.gz
- Upload date:
- Size: 5.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.4 CPython/3.14.4 Linux/5.14.0-611.47.1.el9_7.x86_64
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e0345db2da961b7a2cba2e60bc33618e7226e013ad8502aee8c0515a82e2a74b
|
|
| MD5 |
d9e92d8260bd8e1e91590c6fadad3d1e
|
|
| BLAKE2b-256 |
9286f622e18ef1f7964434a6065e7e8d9dc8bc54a5f45ef6c667cbc92722e45c
|
File details
Details for the file grapicli-0.5.0-py3-none-any.whl.
File metadata
- Download URL: grapicli-0.5.0-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.4 CPython/3.14.4 Linux/5.14.0-611.47.1.el9_7.x86_64
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
55b443326061bfb7b5399d1c478e4a3790a8f9d672d35c569d06cc432ddb2567
|
|
| MD5 |
fc45350f59b29e6362979b295e4c8c36
|
|
| BLAKE2b-256 |
5d1f64a5770c3cee141946d237e5838f7761d217b93805b8fc473ab6a6644404
|