ActivityWatch includes a simple scripting language for querying event data stored in your local buckets. You can use it to filter out idle time, aggregate events by application, apply category rules, and produce exactly the summary you need — either interactively in the built-in Query Explorer or programmatically via theDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/ActivityWatch/activitywatch/llms.txt
Use this file to discover all available pages before exploring further.
POST /api/0/query/ endpoint. The query language is the same engine that powers the dashboard views, so anything the dashboard shows can be reproduced and extended with a custom query.
Opening the Query Explorer
Navigate tohttp://localhost:5600/#/query in your browser. The Query Explorer provides a text editor for writing queries, a time-range selector, and a results pane that displays the returned events as a table and a duration chart.
Bucket IDs include the hostname of the machine, for example
aw-watcher-window_myhostname. To find the exact IDs for your buckets, open the Buckets page of the dashboard at http://localhost:5600/#/buckets and copy the ID from there before writing your first query.Query language basics
A query is a list of statements separated by semicolons. Each statement assigns the result of a function call to a variable. The final statement must assign to the special variableRETURN, which tells the server what to send back as the query result.
Common query functions
| Function | Description |
|---|---|
query_bucket(bucket_id) | Fetch all events from the named bucket for the selected time period. |
filter_keyvals(events, key, values) | Keep only events where data[key] is one of the values in the list. |
filter_period_intersect(events, filter_events) | Keep only events that overlap in time with at least one event in filter_events. Use this to subtract AFK time. |
merge_events_by_keys(events, keys) | Merge consecutive events that share the same values for the specified keys, summing their durations. |
sort_by_duration(events) | Sort events in descending order by duration. |
limit_events(events, count) | Return only the first count events. |
categorize(events, rules) | Classify events using a list of category rules. Each rule is a list of the form [pattern, category_name]. |
Using the API
You can run queries from any HTTP client by sending aPOST request to /api/0/query/. The request body is a JSON object with a query array (one string per statement) and a timeperiods array specifying the time range.
timestamp, duration, and data fields. Time periods follow ISO 8601 interval notation: start/end.
The
aw-client Python library wraps the query API with a convenient query method, so you can run queries from Python scripts without constructing raw HTTP requests. See the developer guide for usage examples.Data model
Understand buckets, events, and how data is structured in aw-server.
API reference
Full REST API documentation for the query endpoint.
