Query historical data
Infrahub’s immutable history allows you to query the state of your infrastructure at any point in time. This guide shows you how to use temporal queries to access historical data, analyze changes, and understand past configurations.Prerequisites
Before querying historical data, ensure you have:- Access to an Infrahub instance with historical data
- GraphQL API access or SDK installed
- Understanding of timestamps and time formats
Understand temporal queries
Infrahub tracks every change with an immutable timestamp. Temporal queries allow you to:- View infrastructure state at a specific point in time
- Compare configurations before and after changes
- Analyze historical trends and patterns
- Investigate security incidents or unexpected changes
- Meet compliance requirements with complete audit trails
backend/infrahub/core/branch/models.py:219 for the get_branches_and_times_to_query implementation.
Query data at a specific time
Retrieve the state of objects as they existed at a specific timestamp.Using GraphQL with the at parameter
at: ISO 8601 timestamp (e.g.,"2026-02-15T10:30:00Z")
Using the Python SDK
Time format
Timestamps must be in ISO 8601 format: Valid formats:2026-02-15T10:30:00Z(UTC)2026-02-15T10:30:00+00:00(UTC with offset)2026-02-15T05:30:00-05:00(EST with offset)2026-02-15T10:30:00.123456Z(with microseconds)
2026-02-15(date only, missing time)10:30:00(time only, missing date)02/15/2026 10:30(US date format)
Query a single object’s history
Retrieve a specific object as it existed at different points in time.Current state
Historical state
Compare data across time
Query the same data at different timestamps to see how it changed.Using multiple queries
Using the Python SDK
Query branch history
Each branch maintains its own timeline. Query historical data within a specific branch.Query a branch at a specific time
branch: Name of the branch to queryat: Timestamp to query
feature-network-redesign branch at the specified time.
Using the Python SDK with branches
Query attribute history
Retrieve the history of changes to specific attributes.Query attribute values over time
Access historical attribute values
Query relationship history
Retrieve relationships between objects as they existed at specific times.Current relationships
Historical relationships
Common use cases
Audit who changed what and when
Track changes to critical infrastructure:Investigate security incidents
Determine the state of infrastructure before and after an incident:Compliance reporting
Generate reports showing infrastructure state at specific audit dates:Analyze configuration drift
Compare configurations across time to identify drift:Limitations and considerations
Query performance
Historical queries may be slower than current-state queries because:- The database must reconstruct object state at the specified time
- Branch isolation requires querying multiple timelines
- Complex relationships increase computation time
- Querying specific objects instead of all objects
- Limiting the number of relationships retrieved
- Using filters to reduce result sets
Branch-aware vs. branch-agnostic data
Branch-agnostic data exists globally across all branches and times:Verify historical data
Confirm that historical queries return expected results:updated_attimestamps are at or before the query timestamp- Values match expected historical state
- Objects that didn’t exist at the query time return null
Related resources
- Work with branches - Create and manage branches
- Proposed changes - Review and merge changes
- Immutable history topic - Understand how Infrahub tracks changes
- Branching topic - Learn about temporal queries in branches