-
Notifications
You must be signed in to change notification settings - Fork 7
Overview page sdk #853
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+156
−21
Merged
Overview page sdk #853
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7b26abf
Draft overview page sdk
BaptisteGi 58b5dc0
refresh sdk overview
BaptisteGi 3c0426a
spelling
BaptisteGi 7ac5e73
Add product context
BaptisteGi 5adcc05
Merge branch 'stable' into bgi-overview-page
BaptisteGi 9cb30a5
Apply suggestion from @BaptisteGi
BaptisteGi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -138,3 +138,4 @@ yamllint | |
| YouTube | ||
| vscode | ||
| VSCode | ||
| walkthrough | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,37 +1,157 @@ | ||
| --- | ||
| title: Python SDK | ||
| title: Python SDK overview | ||
| --- | ||
| import VideoPlayer from '../../src/components/VideoPlayer'; | ||
| import Tabs from '@theme/Tabs'; | ||
| import TabItem from '@theme/TabItem'; | ||
| import ReferenceLink from '@site/src/components/Card'; | ||
| import VideoPlayer from '@site/src/components/VideoPlayer'; | ||
|
|
||
| The Infrahub Python SDK greatly simplifies how you can interact with Infrahub programmatically. | ||
| # Infrahub Python SDK | ||
|
|
||
| ## Videos | ||
| The Infrahub Python SDK is a client library for interacting with [Infrahub](https://docs.infrahub.app/) programmatically. It handles authentication, query construction, and data serialization so you can work with infrastructure data using native Python objects instead of raw API calls. | ||
|
|
||
| ## What you can do with it | ||
|
|
||
| The SDK covers three main use cases: | ||
|
|
||
| - **Automate inside Infrahub** — Write [transforms](https://docs.infrahub.app/topics/transformation), [generators](https://docs.infrahub.app/topics/generator), and [checks](https://docs.infrahub.app/topics/check) that run as part of Infrahub's pipeline. | ||
| - **Integrate with external systems** — Query and sync data between Infrahub and your existing tools. | ||
| - **Build custom applications** — Use Infrahub as a data backend for your own Python projects. | ||
|
|
||
| Under the hood, tools like [`infrahubctl`](/infrahubctl/infrahubctl) and the [Infrahub Ansible collection](https://docs.infrahub.app/ansible) both use this SDK. | ||
|
|
||
| ## A quick look | ||
|
|
||
| <Tabs groupId="async-sync"> | ||
| <TabItem value="Async" default> | ||
|
|
||
| ```python | ||
| import asyncio | ||
| from infrahub_sdk import InfrahubClient | ||
|
|
||
|
|
||
| async def main(): | ||
| client = InfrahubClient() | ||
|
|
||
| # Create a new tag and save it | ||
| tag = await client.create( | ||
| kind="BuiltinTag", | ||
| name="staging", | ||
| description="Resources in the staging environment", | ||
| ) | ||
| await tag.save() | ||
|
|
||
| # Query all tags | ||
| tags = await client.all(kind="BuiltinTag") | ||
| for tag in tags: | ||
| print(f"{tag.name.value} — {tag.description.value}") | ||
|
|
||
|
|
||
| asyncio.run(main()) | ||
|
|
||
| ``` | ||
|
|
||
| </TabItem> | ||
| <TabItem value="Sync"> | ||
|
|
||
| ```python | ||
| from infrahub_sdk import InfrahubClientSync | ||
|
|
||
| client = InfrahubClientSync() | ||
|
|
||
| # Create a new tag and save it | ||
| tag = client.create( | ||
| kind="BuiltinTag", | ||
| name="staging", | ||
| description="Resources in the staging environment", | ||
| ) | ||
| tag.save() | ||
|
|
||
| # Query all tags | ||
| tags = client.all(kind="BuiltinTag") | ||
| for tag in tags: | ||
| print(f"{tag.name.value} — {tag.description.value}") | ||
|
|
||
| ``` | ||
|
|
||
| </TabItem> | ||
| </Tabs> | ||
|
|
||
| Both async and sync clients expose the same API. Choose async for applications that benefit from concurrent I/O (transforms, large-scale sync scripts) and sync for straightforward scripting. | ||
|
|
||
| ## When to use the SDK instead of direct API calls | ||
|
|
||
| | Concern | Raw API | SDK | | ||
| | ------- | ------- | --- | | ||
| | Authentication | Manual token management, JWT refresh | Handled automatically | | ||
| | Querying | Build GraphQL queries by hand | `client.get()`, `client.all()`, `client.filters()` | | ||
| | Mutations | Construct and POST GraphQL mutations | `node.save()`, `node.delete()` | | ||
| | Concurrency | Roll your own async batching | Built-in `batch` with concurrency control | | ||
| | Typing | Maintain type definitions manually | Schema-driven type export using protocols | | ||
|
|
||
| :::tip | ||
| The SDK removes the boilerplate so you can focus on the logic that matters to your infrastructure. | ||
| ::: | ||
|
|
||
| ## Key capabilities | ||
|
|
||
| - **CRUD operations** — Create, read, update, and delete any node type defined in your schema. | ||
| - **Batch execution** — Group multiple queries into a batch with configurable concurrency limits. | ||
| - **Tracking** — Tag operations with identifiers for auditing and idempotent updates. | ||
| - **Store** — Cache retrieved nodes locally to reduce redundant queries. | ||
| - **GraphQL escape hatch** — Run arbitrary GraphQL queries when the high-level API doesn't cover your use case. | ||
|
|
||
| ## Video walkthrough | ||
|
|
||
| <center> | ||
| <VideoPlayer url='https://www.youtube.com/live/RbRz8_t0FBs?feature=shared' light /> | ||
| </center> | ||
|
|
||
| ## Blog posts | ||
| ## Installation | ||
|
|
||
| <Tabs groupId="installation"> | ||
| <TabItem value="uv" default> | ||
|
|
||
| ```bash | ||
| uv add infrahub-sdk | ||
| ``` | ||
|
|
||
| Extras are available for additional functionality: | ||
|
|
||
| ```bash | ||
| uv add 'infrahub-sdk[ctl]' # Adds the infrahubctl CLI | ||
| uv add 'infrahub-sdk[tests]' # Adds the testing framework for transforms and checks | ||
| uv add 'infrahub-sdk[all]' # Everything | ||
| ``` | ||
|
|
||
| </TabItem> | ||
| <TabItem value="pip"> | ||
|
|
||
| - [Querying Data in Infrahub via the Python SDK](https://www.opsmill.com/querying-data-in-infrahub-via-the-python-sdk/) | ||
| - [Creating, Modifying, and Deleting Data in Infrahub Using the Python SDK](https://www.opsmill.com/infrahub-python-sdk-create-modify-delete/) | ||
| ```bash | ||
| pip install infrahub-sdk | ||
| ``` | ||
|
|
||
| ## Guides | ||
| Extras are available for additional functionality: | ||
|
|
||
| - [Installing infrahub-sdk](./guides/installation.mdx) | ||
| - [Creating a client](./guides/client.mdx) | ||
| - [Querying data in Infrahub](./guides/query_data.mdx) | ||
| - [Managing nodes](./guides/create_update_delete.mdx) | ||
| - [Managing branches](./guides/branches.mdx) | ||
| - [Using the client store](./guides/store.mdx) | ||
| - [Using the client tracking mode](./guides/tracking.mdx) | ||
| ```bash | ||
| pip install 'infrahub-sdk[ctl]' # Adds the infrahubctl CLI | ||
| pip install 'infrahub-sdk[tests]' # Adds the testing framework for transforms and checks | ||
| pip install 'infrahub-sdk[all]' # Everything | ||
| ``` | ||
|
|
||
| ## Topics | ||
| </TabItem> | ||
| </Tabs> | ||
|
|
||
| - [Understanding tracking in the Python SDK](./topics/tracking.mdx) | ||
| <ReferenceLink title="Installation guide" url="/python-sdk/guides/installation" /> | ||
|
|
||
| ## Reference | ||
| ## Next steps | ||
|
|
||
| - [Client configuration](./reference/config.mdx) | ||
| - [Compatibility matrix](./reference/compatibility.mdx) | ||
| - [Python SDK Release Notes](https://github.com/opsmill/infrahub-sdk-python/releases) | ||
| - **[Hello world example](./guides/client.mdx#hello-world-example)** — Your first client connection and query. | ||
| - **[Create and configure a client](./guides/client.mdx)** — Set up authentication, proxy settings, and client options. | ||
| - **[Query data](./guides/query_data.mdx)** — Retrieve nodes with filters and GraphQL. | ||
| - **[Create, update, and delete nodes](./guides/create_update_delete.mdx)** — Manage infrastructure data programmatically. | ||
| - **[Work with branches](./guides/branches.mdx)** — Use Infrahub's branch workflow from Python. | ||
| - **[Batch operations](./guides/batch.mdx)** — Optimize performance for bulk operations. | ||
| - **[Client configuration reference](./reference/config.mdx)** — All available configuration options. | ||
| - **[Compatibility matrix](./reference/compatibility.mdx)** | ||
| - **[Python SDK Release Notes](https://github.com/opsmill/infrahub-sdk-python/releases)** |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.