infrahub_sdk.client
Classes​
InfrahubClient​
GraphQL Client to interact with Infrahub.
Methods:
get​
get(self, kind: type[SchemaType], raise_when_missing: Literal[False], at: Timestamp | None = ..., branch: str | None = ..., timeout: int | None = ..., id: str | None = ..., hfid: list[str] | None = ..., include: list[str] | None = ..., exclude: list[str] | None = ..., populate_store: bool = ..., fragment: bool = ..., prefetch_relationships: bool = ..., property: bool = ..., include_metadata: bool = ..., query_name: str | None = ..., **kwargs: Any) -> SchemaType | None
Show 6 other overloads
get​
get(self, kind: type[SchemaType], raise_when_missing: Literal[True], at: Timestamp | None = ..., branch: str | None = ..., timeout: int | None = ..., id: str | None = ..., hfid: list[str] | None = ..., include: list[str] | None = ..., exclude: list[str] | None = ..., populate_store: bool = ..., fragment: bool = ..., prefetch_relationships: bool = ..., property: bool = ..., include_metadata: bool = ..., query_name: str | None = ..., **kwargs: Any) -> SchemaType
get​
get(self, kind: type[SchemaType], raise_when_missing: bool = ..., at: Timestamp | None = ..., branch: str | None = ..., timeout: int | None = ..., id: str | None = ..., hfid: list[str] | None = ..., include: list[str] | None = ..., exclude: list[str] | None = ..., populate_store: bool = ..., fragment: bool = ..., prefetch_relationships: bool = ..., property: bool = ..., include_metadata: bool = ..., query_name: str | None = ..., **kwargs: Any) -> SchemaType
get​
get(self, kind: str, raise_when_missing: Literal[False], at: Timestamp | None = ..., branch: str | None = ..., timeout: int | None = ..., id: str | None = ..., hfid: list[str] | None = ..., include: list[str] | None = ..., exclude: list[str] | None = ..., populate_store: bool = ..., fragment: bool = ..., prefetch_relationships: bool = ..., property: bool = ..., include_metadata: bool = ..., query_name: str | None = ..., **kwargs: Any) -> InfrahubNode | None
get​
get(self, kind: str, raise_when_missing: Literal[True], at: Timestamp | None = ..., branch: str | None = ..., timeout: int | None = ..., id: str | None = ..., hfid: list[str] | None = ..., include: list[str] | None = ..., exclude: list[str] | None = ..., populate_store: bool = ..., fragment: bool = ..., prefetch_relationships: bool = ..., property: bool = ..., include_metadata: bool = ..., query_name: str | None = ..., **kwargs: Any) -> InfrahubNode
get​
get(self, kind: str, raise_when_missing: bool = ..., at: Timestamp | None = ..., branch: str | None = ..., timeout: int | None = ..., id: str | None = ..., hfid: list[str] | None = ..., include: list[str] | None = ..., exclude: list[str] | None = ..., populate_store: bool = ..., fragment: bool = ..., prefetch_relationships: bool = ..., property: bool = ..., include_metadata: bool = ..., query_name: str | None = ..., **kwargs: Any) -> InfrahubNode
get​
get(self, kind: str | type[SchemaType], raise_when_missing: bool = True, at: Timestamp | None = None, branch: str | None = None, timeout: int | None = None, id: str | None = None, hfid: list[str] | None = None, include: list[str] | None = None, exclude: list[str] | None = None, populate_store: bool = True, fragment: bool = False, prefetch_relationships: bool = False, property: bool = False, include_metadata: bool = False, query_name: str | None = None, **kwargs: Any) -> InfrahubNode | SchemaType | None
delete​
delete(self, kind: str | type[SchemaType], id: str, branch: str | None = None) -> None
create​
create(self, kind: str | type[SchemaType], data: dict | None = None, branch: str | None = None, timeout: int | None = None, **kwargs: Any) -> InfrahubNode | SchemaType
Show 2 other overloads
get_version​
get_version(self) -> str
Return the Infrahub version.
get_user​
get_user(self) -> dict
Return user information.
get_user_permissions​
get_user_permissions(self) -> dict
Return user permissions.
count​
count(self, kind: str | type[SchemaType], at: Timestamp | None = None, branch: str | None = None, timeout: int | None = None, partial_match: bool = False, query_name: str | None = None, **kwargs: Any) -> int
Return the number of nodes of a given kind.
traverse_paths​
traverse_paths(self, source: str | InfrahubNode, destination: str | InfrahubNode) -> PathTraversalResult
Find the shortest path(s) between two nodes in the graph.
Kind filters (kind_filter, excluded_kinds, included_kinds) accept
kind-name strings and/or generated protocol classes. relationship_filter
matches schema relationship identifiers (for example dcimconnector__dcimendpoint),
not the per-side names shown in the result.
Requires Infrahub 1.10 or later.
Args:
source: Node to start from, as a UUID string or anInfrahubNodeinstance.destination: Node to reach, as a UUID string or anInfrahubNodeinstance.max_depth: Maximum number of relationship hops to explore.max_paths: Maximum number of paths to return.kind_filter: Only traverse through nodes of these kinds.relationship_filter: Only traverse through these schema relationship identifiers.excluded_namespaces: Schema namespaces to exclude from traversal.excluded_kinds: Node kinds to exclude from traversal.included_kinds: Node kinds to re-include when otherwise excluded by default.branch: Name of the branch to query from. Defaults to default_branch.at: Time of the query. Defaults to now.timeout: Overrides the default GraphQL timeout, in seconds.
Raises:
VersionNotSupportedError: If the server does not support graph traversal (pre-1.10).GraphQLError: When the GraphQL response contains errors (e.g. unknown node).
path_exists​
path_exists(self, source: str | InfrahubNode, destination: str | InfrahubNode) -> bool
Return whether at least one path connects source to destination.
Convenience wrapper around :meth:traverse_paths for checks: it requests a single
path (the cheapest way to answer "is there a path?") and returns True if one was
found. Accepts the same source/destination and filter arguments as traverse_paths.
Requires Infrahub 1.10 or later.
Args:
source: Node to start from, as a UUID string or anInfrahubNodeinstance.destination: Node to reach, as a UUID string or anInfrahubNodeinstance.max_depth: Maximum number of relationship hops to explore.kind_filter: Only traverse through nodes of these kinds.relationship_filter: Only traverse through these schema relationship identifiers.excluded_namespaces: Schema namespaces to exclude from traversal.excluded_kinds: Node kinds to exclude from traversal.included_kinds: Node kinds to re-include when otherwise excluded by default.branch: Name of the branch to query from. Defaults to default_branch.at: Time of the query. Defaults to now.timeout: Overrides the default GraphQL timeout, in seconds.
Raises:
VersionNotSupportedError: If the server does not support graph traversal (pre-1.10).GraphQLError: When the GraphQL response contains errors (e.g. unknown node).
reachable_nodes​
reachable_nodes(self, source: str | InfrahubNode, target_kinds: list[str | type[SchemaType]]) -> ReachableNodesResult
Find all nodes of the given kinds reachable from a source node.
target_kinds accepts kind-name strings and/or generated protocol classes.
Requires Infrahub 1.10 or later.
Args:
source: Node to start from, as a UUID string or anInfrahubNodeinstance.target_kinds: Kinds of nodes to look for, as kind-name strings or protocol classes.max_depth: Maximum number of relationship hops to explore.max_results: Maximum number of reachable nodes to return.max_paths: Maximum number of paths to compute per reachable node.shortest_paths_only: When True, only return the shortest path(s) to each node.branch: Name of the branch to query from. Defaults to default_branch.at: Time of the query. Defaults to now.timeout: Overrides the default GraphQL timeout, in seconds.
Raises:
VersionNotSupportedError: If the server does not support graph traversal (pre-1.10).GraphQLError: When the GraphQL response contains errors (e.g. unknown node).
all​
all(self, kind: type[SchemaType], at: Timestamp | None = ..., branch: str | None = ..., timeout: int | None = ..., populate_store: bool = ..., offset: int | None = ..., limit: int | None = ..., include: list[str] | None = ..., exclude: list[str] | None = ..., fragment: bool = ..., prefetch_relationships: bool = ..., property: bool = ..., parallel: bool = ..., order: Order | None = ..., include_metadata: bool = ..., query_name: str | None = ...) -> list[SchemaType]
Show 2 other overloads
all​
all(self, kind: str, at: Timestamp | None = ..., branch: str | None = ..., timeout: int | None = ..., populate_store: bool = ..., offset: int | None = ..., limit: int | None = ..., include: list[str] | None = ..., exclude: list[str] | None = ..., fragment: bool = ..., prefetch_relationships: bool = ..., property: bool = ..., parallel: bool = ..., order: Order | None = ..., include_metadata: bool = ..., query_name: str | None = ...) -> list[InfrahubNode]
all​
all(self, kind: str | type[SchemaType], at: Timestamp | None = None, branch: str | None = None, timeout: int | None = None, populate_store: bool = True, offset: int | None = None, limit: int | None = None, include: list[str] | None = None, exclude: list[str] | None = None, fragment: bool = False, prefetch_relationships: bool = False, property: bool = False, parallel: bool = False, order: Order | None = None, include_metadata: bool = False, query_name: str | None = None) -> list[InfrahubNode] | list[SchemaType]
Retrieve all nodes of a given kind.
Args:
kind: kind of the nodes to queryat: Time of the query. Defaults to Now.branch: Name of the branch to query from. Defaults to default_branch.populate_store: Flag to indicate whether to populate the store with the retrieved nodes.timeout: Overrides default timeout used when querying the GraphQL API. Specified in seconds.offset: The offset for pagination.limit: The limit for pagination.include: List of attributes or relationships to include in the query.exclude: List of attributes or relationships to exclude from the query.fragment: Flag to use GraphQL fragments for generic schemas.prefetch_relationships: Flag to indicate whether to pre-fetch related node data.parallel: Whether to use parallel processing for the query.order: Ordering related options. Settingdisable=Trueenhances performances.include_metadata: If True, includes node_metadata and relationship_metadata in the query.query_name: If provided is used as the GraphQL operation name else All_<kind> is used.
Returns:
- list[InfrahubNode]: List of Nodes
filters​
filters(self, kind: type[SchemaType], at: Timestamp | None = ..., branch: str | None = ..., timeout: int | None = ..., populate_store: bool = ..., offset: int | None = ..., limit: int | None = ..., include: list[str] | None = ..., exclude: list[str] | None = ..., fragment: bool = ..., prefetch_relationships: bool = ..., partial_match: bool = ..., property: bool = ..., parallel: bool = ..., order: Order | None = ..., include_metadata: bool = ..., query_name: str | None = ..., **kwargs: Any) -> list[SchemaType]
Show 2 other overloads
filters​
filters(self, kind: str, at: Timestamp | None = ..., branch: str | None = ..., timeout: int | None = ..., populate_store: bool = ..., offset: int | None = ..., limit: int | None = ..., include: list[str] | None = ..., exclude: list[str] | None = ..., fragment: bool = ..., prefetch_relationships: bool = ..., partial_match: bool = ..., property: bool = ..., parallel: bool = ..., order: Order | None = ..., include_metadata: bool = ..., query_name: str | None = ..., **kwargs: Any) -> list[InfrahubNode]
filters​
filters(self, kind: str | type[SchemaType], at: Timestamp | None = None, branch: str | None = None, timeout: int | None = None, populate_store: bool = True, offset: int | None = None, limit: int | None = None, include: list[str] | None = None, exclude: list[str] | None = None, fragment: bool = False, prefetch_relationships: bool = False, partial_match: bool = False, property: bool = False, parallel: bool = False, order: Order | None = None, include_metadata: bool = False, query_name: str | None = None, **kwargs: Any) -> list[InfrahubNode] | list[SchemaType]
Retrieve nodes of a given kind based on provided filters.
Args:
kind: kind of the nodes to queryat: Time of the query. Defaults to Now.branch: Name of the branch to query from. Defaults to default_branch.timeout: Overrides default timeout used when querying the GraphQL API. Specified in seconds.populate_store: Flag to indicate whether to populate the store with the retrieved nodes.offset: The offset for pagination.limit: The limit for pagination.include: List of attributes or relationships to include in the query.exclude: List of attributes or relationships to exclude from the query.fragment: Flag to use GraphQL fragments for generic schemas.prefetch_relationships: Flag to indicate whether to pre-fetch related node data.partial_match: Allow partial match of filter criteria for the query.parallel: Whether to use parallel processing for the query.order: Ordering related options. Settingdisable=Trueenhances performances.include_metadata: If True, includes node_metadata and relationship_metadata in the query.query_name: If provided is used as the GraphQL operation name else Filters_<kind> is used.**kwargs: Additional filter criteria for the query.
Returns:
- list[InfrahubNodeSync]: List of Nodes that match the given filters.