Target¶
Manager for interacting with target resources.
- class gpp_client.managers.target.TargetManager(client: GPPClient)[source]¶
Bases:
BaseManagerManager for interacting with target resources.
- async clone(*, target_id: str, properties: TargetPropertiesInput | None = None, from_json: str | Path | dict[str, Any] | None = None, replace_in: list[str] | None = None) dict[str, Any][source]¶
Clone an existing target, optionally modifying some properties.
- Parameters:
target_id (str) – Unique identifier of the target to clone.
properties (TargetPropertiesInput, optional) – Properties to override in the cloned target.
from_json (str | Path | dict[str, Any], optional) – JSON representation of the properties. May be a path-like object (
strorPath) to a JSON file, or adictalready containing the JSON data.replace_in (list[str], optional) – List of observation IDs where the cloned target should replace the original target.
- Returns:
The original and newly created target data.
- Return type:
- Raises:
GPPValidationError – If an error is encountered validating the input properties.
GPPClientError – If an unexpected error occurs unpacking the response.
- async create(*, properties: TargetPropertiesInput | None = None, from_json: str | Path | dict[str, Any] | None = None, program_id: str | None = None, proposal_reference: str | None = None, program_reference: str | None = None) dict[str, Any][source]¶
Create a new target using a fully defined
TargetPropertiesInput.- Parameters:
properties (TargetPropertiesInput, optional) – Full target definition. This or
from_jsonmust be supplied.from_json (str | Path | dict[str, Any], optional) – JSON representation of the properties. May be a path-like object (
strorPath) to a JSON file, or adictalready containing the JSON data.program_id (str, optional) – Program ID to associate with. Must be provided if neither proposal_reference nor program_reference is given.
proposal_reference (str, optional) – Reference to a proposal; used as an alternative to program_id.
program_reference (str, optional) – Reference to a program label; used as an alternative to program_id.
- Returns:
The created target and its associated metadata.
- Return type:
- Raises:
GPPValidationError – If an error is encountered validating the input properties or identifiers.
GPPClientError – If an unexpected error occurs unpacking the response.
Notes
At least one of program_id, proposal_reference, or program_reference must be specified to associate with a valid program.
Exactly one of
propertiesorfrom_jsonmust be supplied. Supplying both or neither raisesGPPValidationError.
- async delete_by_id(target_id: str) dict[str, Any][source]¶
Soft-delete a resource by setting its existence to DELETED.
- Parameters:
target_id (str) – Unique identifier of the target.
- Returns:
The delete result payload.
- Return type:
- Raises:
GPPValidationError – If a validation error occurs.
GPPClientError – If an unexpected error occurs unpacking the response.
- async get_all(*, include_deleted: bool = False, where: WhereTarget | None = None, offset: int | None = None, limit: int | None = None) dict[str, Any][source]¶
Get all targets with optional filtering and pagination.
- Parameters:
include_deleted (bool, default=False) – Whether to include deleted resources.
where (WhereTarget, optional) – Optional filter criteria.
offset (int, optional) – Cursor-based offset (by ID).
limit (int, optional) – Maximum number of results.
- Returns:
Dictionary with matches and hasMore keys.
- Return type:
- Raises:
GPPClientError – If an unexpected error occurs unpacking the response.
- async get_by_id(target_id: str, *, include_deleted: bool = False) dict[str, Any][source]¶
Fetch a single resource by ID.
- Parameters:
- Returns:
Retrieved data.
- Return type:
- Raises:
GPPClientError – If an unexpected error occurs unpacking the response.
- get_result(result: dict[str, Any] | None, operation_name: str | None = None) dict[str, Any]¶
Extract the payload for a given GraphQL operation.
- Parameters:
- Returns:
The extracted payload for the specified operation.
- Return type:
- Raises:
GPPClientError – If the result is empty or invalid, or if the specified operation name is not found in the result.
- get_single_result(payload: dict[str, Any], key: str) dict[str, Any]¶
Extract exactly one item from a list-valued field in a GraphQL payload.
- Parameters:
- Returns:
The single item extracted from the field.
- Return type:
- Raises:
GPPClientError – If the specified field is missing from the payload, is not a list, or does not contain exactly one item.
- load_properties(*, properties: Any | None, from_json: str | Path | dict[str, Any] | None, cls: type[T]) T¶
Return a validated properties object from exactly one data source.
- Parameters:
- Returns:
Instance of
clsrepresenting the validated properties.- Return type:
T
- Raises:
GPPValidationError – If validation fails or an error occurs loading the properties.
- raise_error(exc_class: type[GPPError], exc: Exception, *, include_traceback: bool = False) NoReturn¶
Raise a structured exception with contextual information.
- async raise_for_status(response, *, ok_statuses: set[int], default_message: str = 'Request failed') None¶
Raise an exception if the HTTP response status is not OK.
- Parameters:
- Raises:
GPPResponseError – If the response status is not in
ok_statuses.
- resolve_content(*, file_path: str | Path | None, content: bytes | None) bytes¶
Resolve upload content bytes from exactly one source.
- Parameters:
- Returns:
The resolved content bytes.
- Return type:
- Raises:
GPPValidationError – If both or neither of
file_pathandcontentare provided, or iffile_pathis invalid.GPPClientError – If reading the file fails due to an unexpected I/O error.
- async restore_by_id(target_id: str) dict[str, Any][source]¶
Restore a soft-deleted resource by setting its existence to PRESENT.
- Parameters:
target_id (str) – Unique identifier of the target.
- Returns:
The restore result payload.
- Return type:
- Raises:
GPPValidationError – If a validation error occurs.
GPPClientError – If an unexpected error occurs unpacking the response.
- async update_all(*, properties: TargetPropertiesInput | None = None, from_json: str | Path | dict[str, Any] | None = None, where: WhereTarget | None = None, limit: int | None = None, include_deleted: bool = False) dict[str, Any][source]¶
Update one or more targets using a partial or complete
TargetPropertiesInput.- Parameters:
properties (TargetPropertiesInput, optional) – New values to apply to matching targets. This or
from_jsonmust be supplied.from_json (str | Path | dict[str, Any], optional) – JSON representation of the properties. May be a path-like object (
strorPath) to a JSON file, or adictalready containing the JSON data.where (WhereTarget, optional) – Query filters to select which targets to update. If omitted, all targets are eligible.
limit (int, optional) – Maximum number of targets to update. If omitted, all matches are updated.
include_deleted (bool, default=False) – Whether to include soft-deleted targets in the update.
- Returns:
A dictionary containing update results and the updated targets.
- Return type:
- Raises:
GPPValidationError – If an error is encountered validating the input properties.
GPPClientError – If an unexpected error occurs unpacking the response.
Notes
Exactly one of
propertiesorfrom_jsonmust be supplied. Supplying both or neither raisesGPPValidationError.
- async update_by_id(target_id: str, *, properties: TargetPropertiesInput | None = None, from_json: str | Path | dict[str, Any] | None = None, include_deleted: bool = False) dict[str, Any][source]¶
Update a single target by its unique identifier.
- Parameters:
target_id (str) – Unique identifier of the target. This or
from_jsonmust be supplied.properties (TargetPropertiesInput, optional) – New values to apply to the target.
from_json (str | Path | dict[str, Any], optional) – JSON representation of the properties. May be a path-like object (
strorPath) to a JSON file, or adictalready containing the JSON data.include_deleted (bool, default=False) – Whether to include soft-deleted targets in the update.
- Returns:
Dictionary containing update result, including updated target data.
- Return type:
- Raises:
GPPValidationError – If an error is encountered validating the input properties.
GPPClientError – If an unexpected error occurs unpacking the response.
Notes
Exactly one of
propertiesorfrom_jsonmust be supplied. Supplying both or neither raisesGPPValidationError.
- validate_single_identifier(**kwargs) None¶
Validate that exactly one identifier is provided.
This helper checks that exactly one of the provided keyword arguments is non-None. It raises a ValueError otherwise.
- Parameters:
**kwargs (dict[str, Optional[str]]) – A dictionary of identifier keyword arguments to validate.
- Raises:
GPPValidationError – If none or more than one identifiers are provided.