infrahub_sdk.node.node
Classes
InfrahubNode
Represents a Infrahub node in an asynchronous context.
Methods:
from_graphql
from_graphql(cls, client: InfrahubClient, branch: str, data: dict, schema: MainSchemaTypesAPI | None = None, timeout: int | None = None) -> Self
generate
generate(self, nodes: list[str] | None = None) -> None
artifact_generate
artifact_generate(self, name: str) -> None
artifact_fetch
artifact_fetch(self, name: str) -> str | dict[str, Any]
download_file
download_file(self, dest: Path | None = None) -> bytes | int
Download the file content from this FileObject node.
This method is only available for nodes that inherit from CoreFileObject. The node must have been saved (have an id) before calling this method.
Args:
dest: Optional destination path. If provided, the file will be streamed directly to this path (memory-efficient for large files) and the number of bytes written will be returned. If not provided, the file content will be returned as bytes.
Returns:
- If
destis None: The file content as bytes. - If
destis provided: The number of bytes written to the file.
Raises:
FeatureNotSupportedError: If this node doesn't inherit from CoreFileObject.ValueError: If the node hasn't been saved yet or file not found.AuthenticationError: If authentication fails.
Examples:
>>> # Download to memory
>>> content = await contract.download_file()
>>> # Stream to file (memory-efficient for large files)
>>> bytes_written = await contract.download_file(dest=Path("/tmp/contract.pdf"))
delete
delete(self, timeout: int | None = None, request_context: RequestContext | None = None) -> None
save
save(self, allow_upsert: bool = False, update_group_context: bool | None = None, timeout: int | None = None, request_context: RequestContext | None = None) -> None
generate_query_data
generate_query_data(self, filters: dict[str, Any] | None = None, 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, order: Order | None = None, include_metadata: bool = False) -> dict[str, Any | dict]
generate_query_data_node
generate_query_data_node(self, include: list[str] | None = None, exclude: list[str] | None = None, inherited: bool = True, insert_alias: bool = False, prefetch_relationships: bool = False, property: bool = False, include_metadata: bool = False) -> dict[str, Any | dict]
Generate the node part of a GraphQL Query with attributes and nodes.
Args:
include: List of attributes or relationships to include. Defaults to None.exclude: List of attributes or relationships to exclude. Defaults to None.inherited: Indicated of the attributes and the relationships inherited from generics should be included as well. Defaults to True.insert_alias: If True, inserts aliases in the query for each attribute or relationship.prefetch_relationships: If True, pre-fetches relationship data as part of the query.include_metadata: If True, includes node_metadata and relationship_metadata in the query.
Returns:
- dict[str, Union[Any, Dict]]: GraphQL query in dictionary format
add_relationships
add_relationships(self, relation_to_update: str, related_nodes: list[str]) -> None
remove_relationships
remove_relationships(self, relation_to_update: str, related_nodes: list[str]) -> None
create
create(self, allow_upsert: bool = False, timeout: int | None = None, request_context: RequestContext | None = None) -> None
update
update(self, do_full_update: bool = False, timeout: int | None = None, request_context: RequestContext | None = None) -> None
get_pool_allocated_resources
get_pool_allocated_resources(self, resource: InfrahubNode) -> list[InfrahubNode]
Fetch all nodes that were allocated for the pool and a given resource.
Args:
resource: The resource from which the nodes were allocated.
Returns:
- list[InfrahubNode]: The allocated nodes.
get_pool_resources_utilization
get_pool_resources_utilization(self) -> list[dict[str, Any]]
Fetch the utilization of each resource for the pool.
Returns:
- list[dict[str, Any]]: A list containing the allocation numbers for each resource of the pool.
get_flat_value
get_flat_value(self, key: str, separator: str = '__') -> Any
Query recursively a value defined in a flat notation (string), on a hierarchy of objects
Examples:
name__value module.object.value
extract
extract(self, params: dict[str, str]) -> dict[str, Any]
Extract some data points defined in a flat notation.
InfrahubNodeSync
Represents a Infrahub node in a synchronous context.
Methods:
from_graphql
from_graphql(cls, client: InfrahubClientSync, branch: str, data: dict, schema: MainSchemaTypesAPI | None = None, timeout: int | None = None) -> Self
generate
generate(self, nodes: list[str] | None = None) -> None
artifact_generate
artifact_generate(self, name: str) -> None