Prerequisites
- Python 3.12+ installed
- Infrahub SDK installed (see Installation)
- Access to an Infrahub instance
- API token (optional, for authentication)
Basic Example
Create a file namedquickstart.py:
Configuration
Using Environment Variables
Set environment variables before running:Using Configuration Object
Pass configuration directly to the client:Using Configuration File
Createinfrahub.toml:
Creating Objects
Create a new device:Querying Data
Get a Single Object
Get All Objects
Filter Results
Updating Objects
Update an existing object:Working with Relationships
Create objects with relationships:Using Branches
Work with different branches:Error Handling
Handle errors gracefully:Using the CLI Tool
The SDK includesinfrahubctl for running scripts:
Complete Example
Here’s a complete example that creates a site and devices:Next Steps
Client Configuration
Learn more about configuring the InfrahubClient
Queries
Advanced querying techniques
Mutations
Creating and updating data
Batch Operations
Efficient bulk operations