What is reports as code?
Reports as code means keeping each recurring report as plain-text files, SQL for the data and YAML for the layout and delivery, in version control. A tool validates, runs and delivers them. It is the same idea that infrastructure as code brought to servers and dbt brought to data transformation, applied to the reports people receive.
The principles
Plain text
A report is SQL for the data and YAML for the shape and the delivery. No GUI, no binary files.
In git
Every change is a commit: reviewed in a pull request, with history, blame and a way back.
Declared, not scripted
You say what the file looks like and where it goes; the tool does the work the same way for every report.
Checked before it runs
The project is validated and its SQL compiled before anything reaches a database or an inbox.
One definition, many environments
The same report runs against dev and prod, and for every client or region, by configuration.
Run by automation
An orchestrator runs it on time; nobody has to remember to send it.
An example
A monthly sales workbook with one tab per query, money formatted, emailed to finance. With DRE it is two files and one command.
select region, count(*) as orders, sum(amount) as net
from {{ source('shop', 'orders') }}
where order_date between '{{ run.date.prev_month.start.date }}'
and '{{ run.date.prev_month.end.date }}'
group by region
order by net descqueries:
- {query: sales, tab_name: By region}
output:
format: xlsx
columns:
net: {format: "#,##0.00"}
destination:
profile: mail
to: finance@example.com
subject: "Sales {{ run.date.prev_month.start.date }}"dre validate -s sales # check it, and see where the file will go
dre run sales # build the workbook and send itThe lifecycle of a report
What happens to one report change, from the first line of SQL to a rerun months later:
Write
SQL selects the data; YAML names the tabs, column formats, totals, template and destinations. Both sit in one folder per report.
Validate
dre validatechecks every key, compiles the SQL and shows where each file would go, before anything reaches a database or an inbox.Review
The change goes through a pull request. Reviewers read a diff of SQL and YAML, not a binary report file or a screenshot.
Preview
dre run --previewbuilds the output from real data (the first 100 rows by default) without delivering it, so the reviewer can open the actual workbook or PDF.Run on schedule
Your orchestrator (cron, Airflow, Dagster, Databricks Jobs) runs
dre run --schedule …; named schedules live next to the report.Deliver and record
The file goes to email, SFTP, a bucket or Slack, and
run_results.jsonrecords what ran, with which variables, and where every file went.Rerun
Months later,
DRE_RUN_ATreruns a report for its original period, so “send September again” gives September’s numbers.
Reports as code and dashboards
Dashboards answer questions people come to ask. Recurring reports go to people who never open the dashboard: a finance team that needs the month-end workbook in its own format, a bank that needs a fixed-width file by 5 pm, members who each need their own statement. Those outputs have exact shapes and deadlines, and they are often built by a script, a report server or a person copying numbers into a template. Reports as code gives them the same review, history and automation that dashboards and data models already have, and keeps the BI tool for what it is good at.
What it isn’t
- Not a dashboard tool: there is nothing to click through, only files and messages that arrive
- Not a transformation tool: it reads tables (including dbt models) and does not build them
- Not a scheduler: your orchestrator decides when; the report says what and where
What it gives you
- A wrong number can be traced to the commit that changed it
- New reports copy a reviewed pattern instead of starting from a blank script
- Anyone who reads SQL can review a report change
- Coding agents can write and change reports, because everything is text
Questions
Is reports as code the same as BI as code?
No. BI as code (for example LookML or dashboard definitions in git) describes interactive dashboards and their semantic models. Reports as code describes the files and messages people receive on a schedule: a workbook, a PDF statement, a bank file, a Slack headline. Many teams use both.
Do I need to know Python?
No. A report is SQL and YAML. The tool does the formatting, delivery, retries and logging that would otherwise be written in a script.
Can people who don’t write code change a report?
They can review it: a change is a readable diff in a pull request. Coding agents with DRE’s skills can also make the change from a plain-English request, for an engineer to review.
How do I start?
Pick one recurring report that is built by hand or by a script today, and rebuild it as SQL and YAML. Getting started walks through a first report in about ten minutes.