Base client#
What every engine inherits: the description of the server it talks to, the preparation of the requests, and the checking of the responses. The status codes each operation accepts are listed here as class attributes.
- class scim2_client.SCIMClient(*, provider: ScimProvider | None = None, resource_models: Collection[type[Resource]] | None = None, resource_types: Collection[ResourceType] | None = None, service_provider_config: ServiceProviderConfig | None = None, check_request_payload: bool = True, check_response_payload: bool = True, check_response_content_type: bool = True, check_response_status_codes: bool = True, raise_scim_errors: bool = True)[source]#
The base model for request clients.
It goal is to parse the requests and responses and check if they comply with the SCIM specifications.
This class can be inherited and used as a basis for request engine integration.
- Parameters:
provider¶ – The
ScimProviderdescribing the server: the models it serves, the endpoints it serves them under, and the capabilities it declares.discover()fills what it does not tell.resource_models¶ – Deprecated, pass a
providerinstead. A collection ofResourcemodels expected to be handled by the SCIM client. If a request payload describe a resource that is not in this list, an exception will be raised.resource_types¶ – Deprecated, pass a
providerinstead. A collection ofResourceTypethat will be used to guess the server endpoints associated with the resources.service_provider_config¶ – Deprecated, pass a
providerinstead. An instance ofServiceProviderConfig.check_request_payload¶ – If
False,resourceis expected to be a dict that will be passed as-is in the request. This value can be overwritten in methods.check_response_payload¶ – Whether to validate that the response payloads are valid. If set, the raw payload will be returned. This value can be overwritten in methods.
check_response_content_type¶ – Whether to validate that the response content types are valid.
check_response_status_codes¶ – Whether to validate that the response status codes are valid.
raise_scim_errors¶ – If
Trueand the server returned anErrorobject during a request, aSCIMExceptionexception will be raised. IfFalsethe error object is returned. This value can be overwritten in methods.
Note
ResourceType,Schemaandscim2_models.ServiceProviderConfigare pre-loaded by default.- CREATION_RESPONSE_STATUS_CODES: list[int] = [201, 409, 307, 308, 400, 401, 403, 404, 500]#
Resource creation HTTP codes.
As defined at RFC7644 §3.3 and RFC7644 §3.12.
- QUERY_RESPONSE_STATUS_CODES: list[int] = [200, 304, 307, 308, 400, 401, 403, 404, 500]#
Resource querying HTTP codes.
As defined at RFC7644 §3.4.2, RFC7644 §3.12 and RFC7644 §3.14.
- SEARCH_RESPONSE_STATUS_CODES: list[int] = [200, 307, 308, 400, 401, 403, 404, 409, 413, 500, 501]#
Resource querying HTTP codes.
As defined at RFC7644 §3.4.3 and RFC7644 §3.12.
- BULK_RESPONSE_STATUS_CODES: list[int] = [200, 307, 308, 400, 401, 403, 404, 409, 413, 500, 501]#
Bulk request HTTP codes.
As defined at RFC7644 §3.7 and RFC7644 §3.12.
200is the only success code, as the individual operation results are carried by the response payload.413is answered when the request exceeds the limits the server advertises, as defined at RFC7644 §3.7.4.412is not expected, since a bulk request is never conditional as a whole.
- DELETION_RESPONSE_STATUS_CODES: list[int] = [204, 307, 308, 400, 401, 403, 404, 409, 412, 500, 501]#
Resource deletion HTTP codes.
As defined at RFC7644 §3.6 and RFC7644 §3.12.
- REPLACEMENT_RESPONSE_STATUS_CODES: list[int] = [200, 307, 308, 400, 401, 403, 404, 409, 412, 500, 501]#
Resource querying HTTP codes.
As defined at RFC7644 §3.4.2 and RFC7644 §3.12.
- PATCH_RESPONSE_STATUS_CODES: list[int] = [200, 204, 307, 308, 400, 401, 403, 404, 409, 412, 500, 501]#
Resource patching HTTP codes.
As defined at RFC7644 §3.5.2 and RFC7644 §3.12.
- property provider: ScimProvider#
The
ScimProviderdescribing the server.
- property resource_types: tuple[ResourceType, ...] | None#
Deprecated, read
providerinstead.
- property service_provider_config: ServiceProviderConfig | None#
Deprecated, read
providerinstead.
- get_resource_model(name: str) type[Resource] | None[source]#
Get a registered model by its name or its schema.
- resource_endpoint(target: type[Resource] | Resource | ResourceType | str | _Me | None) str[source]#
Find the
endpointa request is sent to.- Parameters:
target¶ – A
ResourceType, or its name or id. AResourcemodel goes to the resource type named after its schema. AResourceobject goes to the resource type of itsmeta.resourceType.Megoes to/Me.
- register_naive_resource_types() None[source]#
Register a naive
ResourceTypefor each model theproviderdescribes.This fills the
ResourceTypewith generic values. The endpoint is the resource name with a s suffix. For instance, theUserwill have a /Users endpoint.Deprecated since version 0.9: A
ScimProvidergiven noResourceTypebuilds those values itself. Will be removed in 1.0.
- check_response(payload: dict[str, Any] | None, status_code: int, headers: ResponseHeaders, expected_status_codes: list[int] | None = None, expected_types: Sequence[type[ScimObject]] | None = None, check_response_payload: bool | None = None, raise_scim_errors: bool | None = None, scim_ctx: Context | None = None, target: Resource | None = None) ScimObject | dict[str, Any] | None[source]#
Build the object a server response describes, and check it on the way.
This is what an engine calls once it has performed a request. A failure without
Error, the content type, theErrorthe server may have returned, the status code and the payload are examined in that order.- Parameters:
payload¶ – The decoded body of the response, or
Nonewhen it carried none.status_code¶ – The HTTP status code of the response.
headers¶ – The headers of the response.
expected_status_codes¶ – The status codes the operation defines,
Nonefor any.expected_types¶ – The resource types the operation may return.
check_response_payload¶ – Overrides
check_response_payloadfor this response.raise_scim_errors¶ – Overrides
raise_scim_errorsfor this response.target¶ – The resource the request was made conditional upon, returned as it is when the server answers a
304 Not Modified.
- Raises:
SCIMResponseException – When the response cannot be read as the operation expects.
- build_resource_models(resource_types: Collection[ResourceType], schemas: Collection[Schema]) tuple[type[Resource], ...][source]#
Build models from server objects.
Deprecated since version 0.9: Use
ScimProvider.from_discoveryinstead. Will be removed in 1.0.
- class scim2_client.BaseSyncSCIMClient(*, provider: ScimProvider | None = None, resource_models: Collection[type[Resource]] | None = None, resource_types: Collection[ResourceType] | None = None, service_provider_config: ServiceProviderConfig | None = None, check_request_payload: bool = True, check_response_payload: bool = True, check_response_content_type: bool = True, check_response_status_codes: bool = True, raise_scim_errors: bool = True)[source]#
Base class for synchronous request clients.
- create(target: ResourceT, resource: None = None, check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [201, 409, 307, 308, 400, 401, 403, 404, 500], raise_scim_errors: bool | None = None, **kwargs: Any) ResourceT | Error | dict[str, Any][source]#
- create(target: type[ResourceT], resource: ResourceT | dict[str, Any], check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [201, 409, 307, 308, 400, 401, 403, 404, 500], raise_scim_errors: bool | None = None, **kwargs: Any) ResourceT | Error | dict[str, Any]
- create(target: ResourceType | str | _Me | None, resource: ResourceT, check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [201, 409, 307, 308, 400, 401, 403, 404, 500], raise_scim_errors: bool | None = None, **kwargs: Any) ResourceT | Error | dict[str, Any]
- create(*, resource: ResourceT, check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [201, 409, 307, 308, 400, 401, 403, 404, 500], raise_scim_errors: bool | None = None, **kwargs: Any) ResourceT | Error | dict[str, Any]
- create(target: dict[str, Any] | ResourceType | str | _Me | None = None, resource: dict[str, Any] | None = None, check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [201, 409, 307, 308, 400, 401, 403, 404, 500], raise_scim_errors: bool | None = None, **kwargs: Any) Resource | Error | dict[str, Any]
Perform a POST request to create, as defined in RFC7644 §3.3.
- Parameters:
target¶ – The
ResourceTypeto create the resource in, or its name or id, or aResourcemodel. When omitted, it is the one named after the schema of the resource. The resource itself may be passed here instead ofresource. WithMe, the resource is created under/Me, and the server chooses its resource type.resource¶ – The resource to create. If it is a
dict, it is read with the model passed astarget, or else with the model guessed from its schemas.check_request_payload¶ – If set, overwrites
check_request_payload.check_response_payload¶ – If set, overwrites
check_response_payload.expected_status_codes¶ – The list of expected status codes form the response. If
Noneany status code is accepted.raise_scim_errors¶ – If set, overwrites
raise_scim_errors.kwargs¶ – Additional parameters passed to the underlying HTTP request library.
- Returns:
Creation of a User resource#from scim2_models import User request = User(user_name="bjensen@example.com") response = scim.create(request) # 'response' may be a User or an Error object
Tip
Check the
RESOURCE_CREATION_REQUESTandRESOURCE_CREATION_RESPONSEcontexts to understand which value will excluded from the request payload, and which values are expected in the response payload.
- query(target: _Me, id: ResponseParameters[Any] | dict[str, Any] | None = None, query_parameters: ResponseParameters[Any] | dict[str, Any] | None = None, check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [200, 304, 307, 308, 400, 401, 403, 404, 500], raise_scim_errors: bool | None = None, **kwargs: Any) Resource | Error | dict[str, Any][source]#
- query(target: type[ServiceProviderConfig], id: ResponseParameters[Any] | dict[str, Any] | None = None, query_parameters: ResponseParameters[Any] | dict[str, Any] | None = None, check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [200, 304, 307, 308, 400, 401, 403, 404, 500], raise_scim_errors: bool | None = None, **kwargs: Any) ServiceProviderConfig | Error | dict[str, Any]
- query(target: ResourceType | str, id: str | Resource, query_parameters: ResponseParameters[Any] | dict[str, Any] | None = None, check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [200, 304, 307, 308, 400, 401, 403, 404, 500], raise_scim_errors: bool | None = None, **kwargs: Any) Resource | Error | dict[str, Any]
- query(target: ResourceType | str | None = None, id: ResponseParameters[Any] | dict[str, Any] | None = None, query_parameters: ResponseParameters[Any] | dict[str, Any] | None = None, check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [200, 304, 307, 308, 400, 401, 403, 404, 500], raise_scim_errors: bool | None = None, **kwargs: Any) ListResponse[Resource] | Error | dict[str, Any]
- query(target: type[ResourceT], id: str | ResourceT, query_parameters: ResponseParameters[Any] | dict[str, Any] | None = None, check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [200, 304, 307, 308, 400, 401, 403, 404, 500], raise_scim_errors: bool | None = None, **kwargs: Any) ResourceT | Error | dict[str, Any]
- query(target: ResourceT, id: ResponseParameters[Any] | dict[str, Any] | None = None, query_parameters: ResponseParameters[Any] | dict[str, Any] | None = None, check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [200, 304, 307, 308, 400, 401, 403, 404, 500], raise_scim_errors: bool | None = None, **kwargs: Any) ResourceT | Error | dict[str, Any]
- query(target: type[ResourceT], id: ResponseParameters[Any] | dict[str, Any] | None = None, query_parameters: ResponseParameters[Any] | dict[str, Any] | None = None, check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [200, 304, 307, 308, 400, 401, 403, 404, 500], raise_scim_errors: bool | None = None, **kwargs: Any) ListResponse[TypeVar] | Error | dict[str, Any]
Perform a GET request to read resources, as defined in RFC7644 §3.4.2.
The resource type is designated by
target.When the server supports ETags and a
Resourceobject carrying a version is passed, the read is conditional, and the object itself is returned when the server answers with a304 Not Modified.- Parameters:
target¶ – A
ResourceType, or its name or id, or aResourcemodel, which goes to the resource type named after its schema. AResourceobject stands for both the resource type, read from itsmeta.resourceType, and the id.Mestands for the resource of the authenticated client.id¶ – The id of the resource to read, or a
Resourceobject carrying it. Whentargetis aResourceobject, the query parameters may be passed here.query_parameters¶ – A
ResponseParametersorSearchRequestdetailing the query parameters. UseResponseParameterswhen querying a single resource by id, where onlyattributesandexcludedAttributesare meaningful (RFC 7644 §3.4.1). UseSearchRequestwhen listing resources, to also passfilter,sortBy,sortOrder,startIndexandcount(RFC 7644 §3.4.2). Passcursorinstead ofstartIndexfor cursor-based pagination (RFC 9865 §2). An empty cursor requests the first page. The response gives the cursor of the next page innext_cursor.check_request_payload¶ – If set, overwrites
scim2_client.SCIMClient.check_request_payload.check_response_payload¶ – If set, overwrites
scim2_client.SCIMClient.check_response_payload.expected_status_codes¶ – The list of expected status codes form the response. If
Noneany status code is accepted.raise_scim_errors¶ – If set, overwrites
scim2_client.SCIMClient.raise_scim_errors.kwargs¶ – Additional parameters passed to the underlying HTTP request library.
- Returns:
A
Errorobject in case of error.A target type object in case of success when a single resource is designated, which is the
targetobject itself when the server answers304 Not Modified.A
ListResponse[target]object in case of success otherwise.
Note
Querying a
ServiceProviderConfigwill return a single object, and not aListResponse.- Usage:
Query of a User resource knowing its id#from scim2_models import User response = scim.query(User, "my-user-id") response = scim.query(User(id="my-user-id")) response = scim.query("Employee", "my-user-id") # 'response' may be a User or an Error object
Query of all the User resources filtering the ones with userName starts with john#from scim2_models import User, SearchRequest req = SearchRequest(filter='userName sw "john"') response = scim.query(User, query_parameters=req) # 'response' may be a ListResponse[User] or an Error object
Query of all the available resources#from scim2_models import User response = scim.query() # 'response' may be a ListResponse[Union[User, Group, ...]] or an Error object
Tip
Check the
RESOURCE_QUERY_REQUESTandRESOURCE_QUERY_RESPONSEcontexts to understand which value will excluded from the request payload, and which values are expected in the response payload.
- search(target: type[ResourceT], search_request: SearchRequest[Any] | None = None, check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [200, 307, 308, 400, 401, 403, 404, 409, 413, 500, 501], raise_scim_errors: bool | None = None, **kwargs: Any) ListResponse[TypeVar] | Error | dict[str, Any][source]#
- search(target: SearchRequest[Any] | ResourceType | str | None = None, search_request: SearchRequest[Any] | None = None, check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [200, 307, 308, 400, 401, 403, 404, 409, 413, 500, 501], raise_scim_errors: bool | None = None, **kwargs: Any) ListResponse[Resource] | Error | dict[str, Any]
Perform a POST search request to read all available resources, as defined in RFC7644 §3.4.3.
- Parameters:
target¶ – The
ResourceTypeto search, or its name or id, or aResourcemodel. When omitted, the search covers all the resource types. The search request may be passed here instead ofsearch_request.search_request¶ – An object detailing the search query parameters.
check_request_payload¶ – If set, overwrites
scim2_client.SCIMClient.check_request_payload.check_response_payload¶ – If set, overwrites
scim2_client.SCIMClient.check_response_payload.expected_status_codes¶ – The list of expected status codes form the response. If
Noneany status code is accepted.raise_scim_errors¶ – If set, overwrites
scim2_client.SCIMClient.raise_scim_errors.kwargs¶ – Additional parameters passed to the underlying HTTP request library.
- Returns:
A
Errorobject in case of error.A
ListResponse[resource_model]object in case of success.
- Usage:
Searching for all the resources filtering the ones with id contains with admin#from scim2_models import User, SearchRequest req = SearchRequest(filter='id co "john"') response = scim.search(search_request=search_request) # 'response' may be a ListResponse[User] or an Error object
Tip
Check the
SEARCH_REQUESTandSEARCH_RESPONSEcontexts to understand which value will excluded from the request payload, and which values are expected in the response payload.
- bulk(bulk_request: BulkRequest[Resource] | dict[str, Any] | None = None, check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [200, 307, 308, 400, 401, 403, 404, 409, 413, 500, 501], raise_scim_errors: bool | None = None, **kwargs: Any) BulkResponse[Resource] | Error | dict[str, Any][source]#
Perform a POST bulk request to execute bulk operations, as defined in RFC7644 §3.7.
- Parameters:
bulk_request¶ – An object detailing the bulk request.
check_request_payload¶ – If set, overwrites
scim2_client.SCIMClient.check_request_payload. When it isFalse,bulk_requestis expected to be a dict that will be passed as-is in the request.check_response_payload¶ – If set, overwrites
scim2_client.SCIMClient.check_response_payload.expected_status_codes¶ – The list of expected status codes form the response. If
Noneany status code is accepted.raise_scim_errors¶ – If set, overwrites
scim2_client.SCIMClient.raise_scim_errors.kwargs¶ – Additional parameters passed to the underlying HTTP request library.
- Returns:
A
Errorobject in case of error.A
BulkResponseobject in case of success.
Important
A bulk job the server processed answers
200, whatever the outcome of the operations it carried, as defined at RFC7644 §3.7.3.raise_scim_errorsis about the bulk job itself, so failed operations raise nothing: theirstatusand theErrorobject theirresponsecarries are to be read one by one.- Usage:
Simultaneously creating a User resource and a Group resource containing the user#from scim2_models import ( BulkRequest, BulkOperation, Group, GroupMember, User, ) req = BulkRequest[User | Group]( operations=[ BulkOperation[User]( method="POST", path="/Users", bulk_id="qwerty", data=User(user_name="Alice"), ), BulkOperation[Group]( method="POST", path="/Groups", bulk_id="ytrewq", data=Group( display_name="Tour Guides", members=[GroupMember(type="User", value="bulkId:qwerty")], ), ), ] ) response = scim.bulk(req) # 'response' may be a BulkResponse or an Error object for operation in response.operations: if operation.status >= 400: print(operation.bulk_id, operation.response.detail)
Tip
Check the
BULK_REQUESTandBULK_RESPONSEcontexts to understand which values will be excluded from the request payload, and which values are expected in the response payload.Tip
When the
ServiceProviderConfigis known, the request is checked against the bulk capabilities the server advertises, and a request the server would answer with a413is not sent.
- delete(target: Resource | type[Resource] | ResourceType | str | _Me | None = None, id: str | Resource | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [204, 307, 308, 400, 401, 403, 404, 409, 412, 500, 501], raise_scim_errors: bool | None = None, **kwargs: Any) Error | dict[str, Any] | None[source]#
Perform a DELETE request, as defined in RFC7644 §3.6.
The resource to delete is designated by a resource type and an id, or by a
Resourceobject.- Parameters:
target¶ – A
ResourceType, or its name or id, or aResourcemodel, which goes to the resource type named after its schema. AResourceobject stands for both the resource type, read from itsmeta.resourceType, and the id.Mestands for the resource of the authenticated client.id¶ – The id of the resource to delete, or a
Resourceobject carrying it.check_response_payload¶ – If set, overwrites
scim2_client.SCIMClient.check_response_payload.expected_status_codes¶ – The list of expected status codes form the response. If
Noneany status code is accepted.raise_scim_errors¶ – If set, overwrites
scim2_client.SCIMClient.raise_scim_errors.kwargs¶ – Additional parameters passed to the underlying HTTP request library.
- Returns:
- Usage:
Deleting an User which id is foobar#from scim2_models import User response = scim.delete(User, "foobar") user = scim.query(User, "foobar") response = scim.delete(user) # 'response' may be None, or an Error object
- replace(target: ResourceT, resource: None = None, check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [200, 307, 308, 400, 401, 403, 404, 409, 412, 500, 501], raise_scim_errors: bool | None = None, **kwargs: Any) ResourceT | Error | dict[str, Any][source]#
- replace(target: type[ResourceT], resource: ResourceT | dict[str, Any], check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [200, 307, 308, 400, 401, 403, 404, 409, 412, 500, 501], raise_scim_errors: bool | None = None, **kwargs: Any) ResourceT | Error | dict[str, Any]
- replace(target: ResourceType | str | _Me | None, resource: ResourceT, check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [200, 307, 308, 400, 401, 403, 404, 409, 412, 500, 501], raise_scim_errors: bool | None = None, **kwargs: Any) ResourceT | Error | dict[str, Any]
- replace(*, resource: ResourceT, check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [200, 307, 308, 400, 401, 403, 404, 409, 412, 500, 501], raise_scim_errors: bool | None = None, **kwargs: Any) ResourceT | Error | dict[str, Any]
- replace(target: dict[str, Any] | ResourceType | str | _Me | None = None, resource: dict[str, Any] | None = None, check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [200, 307, 308, 400, 401, 403, 404, 409, 412, 500, 501], raise_scim_errors: bool | None = None, **kwargs: Any) Resource | Error | dict[str, Any]
Perform a PUT request to replace a resource, as defined in RFC7644 §3.5.1.
- Parameters:
target¶ – The
ResourceTypeof the resource, or its name or id, or aResourcemodel. When omitted, it is the one in themeta.resourceTypeof the resource, or else the one named after its schema. The resource itself may be passed here instead ofresource. WithMe, the resource of the authenticated client is replaced.resource¶ – The new resource. It must have an id, unless
targetisMe. If it is adict, it is read with the model passed astarget, or else with the model guessed from its schemas.check_request_payload¶ – If set, overwrites
scim2_client.SCIMClient.check_request_payload.check_response_payload¶ – If set, overwrites
scim2_client.SCIMClient.check_response_payload.expected_status_codes¶ – The list of expected status codes form the response. If
Noneany status code is accepted.raise_scim_errors¶ – If set, overwrites
scim2_client.SCIMClient.raise_scim_errors.kwargs¶ – Additional parameters passed to the underlying HTTP request library.
- Returns:
An
Errorobject in case of error.The updated object as returned by the server in case of success.
- Usage:
Replacement of a User resource#from scim2_models import User user = scim.query(User, "my-used-id") user.display_name = "Fancy New Name" updated_user = scim.replace(user)
Tip
Check the
RESOURCE_REPLACEMENT_REQUESTandRESOURCE_REPLACEMENT_RESPONSEcontexts to understand which value will excluded from the request payload, and which values are expected in the response payload.
- modify(target: ResourceT | type[ResourceT] | ResourceType | str | _Me | None = None, id: str | ResourceT | PatchOp[TypeVar] | dict[str, Any] | None = None, patch_op: PatchOp[TypeVar] | dict[str, Any] | None = None, check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [200, 204, 307, 308, 400, 401, 403, 404, 409, 412, 500, 501], raise_scim_errors: bool | None = None, **kwargs: Any) ResourceT | Error | dict[str, Any] | None[source]#
Perform a PATCH request to modify a resource, as defined in RFC7644 §3.5.2.
The resource to modify is designated by a resource type and an id, or by a
Resourceobject.- Parameters:
target¶ – A
ResourceType, or its name or id, or aResourcemodel, which goes to the resource type named after its schema. AResourceobject stands for both the resource type, read from itsmeta.resourceType, and the id.Mestands for the resource of the authenticated client.id¶ – The id of the resource to modify, or a
Resourceobject carrying it. Whentargetis aResourceobject, the patch operation may be passed here.patch_op¶ – The
PatchOpobject describing the modifications. Must be parameterized with the model of the resource (e.g.,PatchOp[User]for aUser).check_request_payload¶ – If set, overwrites
scim2_client.SCIMClient.check_request_payload.check_response_payload¶ – If set, overwrites
scim2_client.SCIMClient.check_response_payload.expected_status_codes¶ – The list of expected status codes form the response. If
Noneany status code is accepted.raise_scim_errors¶ – If set, overwrites
scim2_client.SCIMClient.raise_scim_errors.kwargs¶ – Additional parameters passed to the underlying HTTP request library.
- Returns:
- Usage:
Modification of a User resource#from scim2_models import User, PatchOp, PatchOperation operation = PatchOperation( op="replace", path="displayName", value="New Display Name" ) patch_op = PatchOp[User](operations=[operation]) response = scim.modify(User, "my-user-id", patch_op) user = scim.query(User, "my-user-id") response = scim.modify(user, patch_op) # 'response' may be a User, None, or an Error object
Tip
Check the
RESOURCE_PATCH_REQUESTandRESOURCE_PATCH_RESPONSEcontexts to understand which value will excluded from the request payload, and which values are expected in the response payload.
- discover(schemas: bool = True, resource_types: bool = True, service_provider_config: bool = True) None[source]#
Dynamically discover the server configuration objects.
Only what the
providerdoes not describe yet is queried, so what the client was given takes precedence over what the server publishes.- Parameters:
resource_types¶ – Whether to discover the
ResourceTypeendpoint.service_provider_config¶ – Whether to discover the
ServiceProviderConfigendpoint.
- Raises:
InvalidServiceDescriptionException – When the objects the server publishes do not describe a coherent service.
- request(method: str, url: str, **kwargs: Any) RawResponse[source]#
Send a request to the server, without any SCIM processing.
Neither the request nor the response is checked, so this is fitted to observe how the server behaves, for instance with an unsupported HTTP method.
- Parameters:
- Returns:
The response of the underlying HTTP request library.
- Raises:
RequestNetworkException – When the request cannot be sent.
- Usage:
Checking that the/Schemasendpoint refusesDELETE#response = scim.request("DELETE", "/Schemas") assert response.status_code == 405
- class scim2_client.BaseAsyncSCIMClient(*, provider: ScimProvider | None = None, resource_models: Collection[type[Resource]] | None = None, resource_types: Collection[ResourceType] | None = None, service_provider_config: ServiceProviderConfig | None = None, check_request_payload: bool = True, check_response_payload: bool = True, check_response_content_type: bool = True, check_response_status_codes: bool = True, raise_scim_errors: bool = True)[source]#
Base class for asynchronous request clients.
- async create(target: ResourceT, resource: None = None, check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [201, 409, 307, 308, 400, 401, 403, 404, 500], raise_scim_errors: bool | None = None, **kwargs: Any) ResourceT | Error | dict[str, Any][source]#
- async create(target: type[ResourceT], resource: ResourceT | dict[str, Any], check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [201, 409, 307, 308, 400, 401, 403, 404, 500], raise_scim_errors: bool | None = None, **kwargs: Any) ResourceT | Error | dict[str, Any]
- async create(target: ResourceType | str | _Me | None, resource: ResourceT, check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [201, 409, 307, 308, 400, 401, 403, 404, 500], raise_scim_errors: bool | None = None, **kwargs: Any) ResourceT | Error | dict[str, Any]
- async create(*, resource: ResourceT, check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [201, 409, 307, 308, 400, 401, 403, 404, 500], raise_scim_errors: bool | None = None, **kwargs: Any) ResourceT | Error | dict[str, Any]
- async create(target: dict[str, Any] | ResourceType | str | _Me | None = None, resource: dict[str, Any] | None = None, check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [201, 409, 307, 308, 400, 401, 403, 404, 500], raise_scim_errors: bool | None = None, **kwargs: Any) Resource | Error | dict[str, Any]
Perform a POST request to create, as defined in RFC7644 §3.3.
- Parameters:
target¶ – The
ResourceTypeto create the resource in, or its name or id, or aResourcemodel. When omitted, it is the one named after the schema of the resource. The resource itself may be passed here instead ofresource. WithMe, the resource is created under/Me, and the server chooses its resource type.resource¶ – The resource to create. If it is a
dict, it is read with the model passed astarget, or else with the model guessed from its schemas.check_request_payload¶ – If set, overwrites
scim2_client.SCIMClient.check_request_payload.check_response_payload¶ – If set, overwrites
scim2_client.SCIMClient.check_response_payload.expected_status_codes¶ – The list of expected status codes form the response. If
Noneany status code is accepted.raise_scim_errors¶ – If set, overwrites
scim2_client.SCIMClient.raise_scim_errors.kwargs¶ – Additional parameters passed to the underlying HTTP request library.
- Returns:
Creation of a User resource#from scim2_models import User request = User(user_name="bjensen@example.com") response = scim.create(request) # 'response' may be a User or an Error object
Tip
Check the
RESOURCE_CREATION_REQUESTandRESOURCE_CREATION_RESPONSEcontexts to understand which value will excluded from the request payload, and which values are expected in the response payload.
- async query(target: _Me, id: ResponseParameters[Any] | dict[str, Any] | None = None, query_parameters: ResponseParameters[Any] | dict[str, Any] | None = None, check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [200, 304, 307, 308, 400, 401, 403, 404, 500], raise_scim_errors: bool | None = None, **kwargs: Any) Resource | Error | dict[str, Any][source]#
- async query(target: type[ServiceProviderConfig], id: ResponseParameters[Any] | dict[str, Any] | None = None, query_parameters: ResponseParameters[Any] | dict[str, Any] | None = None, check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [200, 304, 307, 308, 400, 401, 403, 404, 500], raise_scim_errors: bool | None = None, **kwargs: Any) ServiceProviderConfig | Error | dict[str, Any]
- async query(target: ResourceType | str, id: str | Resource, query_parameters: ResponseParameters[Any] | dict[str, Any] | None = None, check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [200, 304, 307, 308, 400, 401, 403, 404, 500], raise_scim_errors: bool | None = None, **kwargs: Any) Resource | Error | dict[str, Any]
- async query(target: ResourceType | str | None = None, id: ResponseParameters[Any] | dict[str, Any] | None = None, query_parameters: ResponseParameters[Any] | dict[str, Any] | None = None, check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [200, 304, 307, 308, 400, 401, 403, 404, 500], raise_scim_errors: bool | None = None, **kwargs: Any) ListResponse[Resource] | Error | dict[str, Any]
- async query(target: type[ResourceT], id: str | ResourceT, query_parameters: ResponseParameters[Any] | dict[str, Any] | None = None, check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [200, 304, 307, 308, 400, 401, 403, 404, 500], raise_scim_errors: bool | None = None, **kwargs: Any) ResourceT | Error | dict[str, Any]
- async query(target: ResourceT, id: ResponseParameters[Any] | dict[str, Any] | None = None, query_parameters: ResponseParameters[Any] | dict[str, Any] | None = None, check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [200, 304, 307, 308, 400, 401, 403, 404, 500], raise_scim_errors: bool | None = None, **kwargs: Any) ResourceT | Error | dict[str, Any]
- async query(target: type[ResourceT], id: ResponseParameters[Any] | dict[str, Any] | None = None, query_parameters: ResponseParameters[Any] | dict[str, Any] | None = None, check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [200, 304, 307, 308, 400, 401, 403, 404, 500], raise_scim_errors: bool | None = None, **kwargs: Any) ListResponse[TypeVar] | Error | dict[str, Any]
Perform a GET request to read resources, as defined in RFC7644 §3.4.2.
The resource type is designated by
target.When the server supports ETags and a
Resourceobject carrying a version is passed, the read is conditional, and the object itself is returned when the server answers with a304 Not Modified.- Parameters:
target¶ – A
ResourceType, or its name or id, or aResourcemodel, which goes to the resource type named after its schema. AResourceobject stands for both the resource type, read from itsmeta.resourceType, and the id.Mestands for the resource of the authenticated client.id¶ – The id of the resource to read, or a
Resourceobject carrying it. Whentargetis aResourceobject, the query parameters may be passed here.query_parameters¶ – A
ResponseParametersorSearchRequestdetailing the query parameters. UseResponseParameterswhen querying a single resource by id, where onlyattributesandexcludedAttributesare meaningful (RFC 7644 §3.4.1). UseSearchRequestwhen listing resources, to also passfilter,sortBy,sortOrder,startIndexandcount(RFC 7644 §3.4.2). Passcursorinstead ofstartIndexfor cursor-based pagination (RFC 9865 §2). An empty cursor requests the first page. The response gives the cursor of the next page innext_cursor.check_request_payload¶ – If set, overwrites
scim2_client.SCIMClient.check_request_payload.check_response_payload¶ – If set, overwrites
scim2_client.SCIMClient.check_response_payload.expected_status_codes¶ – The list of expected status codes form the response. If
Noneany status code is accepted.raise_scim_errors¶ – If set, overwrites
scim2_client.SCIMClient.raise_scim_errors.kwargs¶ – Additional parameters passed to the underlying HTTP request library.
- Returns:
A
Errorobject in case of error.A target type object in case of success when a single resource is designated, which is the
targetobject itself when the server answers304 Not Modified.A
ListResponse[target]object in case of success otherwise.
Note
Querying a
ServiceProviderConfigwill return a single object, and not aListResponse.- Usage:
Query of a User resource knowing its id#from scim2_models import User response = scim.query(User, "my-user-id") response = scim.query(User(id="my-user-id")) response = scim.query("Employee", "my-user-id") # 'response' may be a User or an Error object
Query of all the User resources filtering the ones with userName starts with john#from scim2_models import User, SearchRequest req = SearchRequest(filter='userName sw "john"') response = scim.query(User, query_parameters=req) # 'response' may be a ListResponse[User] or an Error object
Query of all the available resources#from scim2_models import User response = scim.query() # 'response' may be a ListResponse[Union[User, Group, ...]] or an Error object
Tip
Check the
RESOURCE_QUERY_REQUESTandRESOURCE_QUERY_RESPONSEcontexts to understand which value will excluded from the request payload, and which values are expected in the response payload.
- async search(target: type[ResourceT], search_request: SearchRequest[Any] | None = None, check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [200, 307, 308, 400, 401, 403, 404, 409, 413, 500, 501], raise_scim_errors: bool | None = None, **kwargs: Any) ListResponse[TypeVar] | Error | dict[str, Any][source]#
- async search(target: SearchRequest[Any] | ResourceType | str | None = None, search_request: SearchRequest[Any] | None = None, check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [200, 307, 308, 400, 401, 403, 404, 409, 413, 500, 501], raise_scim_errors: bool | None = None, **kwargs: Any) ListResponse[Resource] | Error | dict[str, Any]
Perform a POST search request to read all available resources, as defined in RFC7644 §3.4.3.
- Parameters:
target¶ – The
ResourceTypeto search, or its name or id, or aResourcemodel. When omitted, the search covers all the resource types. The search request may be passed here instead ofsearch_request.search_request¶ – An object detailing the search query parameters.
check_request_payload¶ – If set, overwrites
scim2_client.SCIMClient.check_request_payload.check_response_payload¶ – If set, overwrites
scim2_client.SCIMClient.check_response_payload.expected_status_codes¶ – The list of expected status codes form the response. If
Noneany status code is accepted.raise_scim_errors¶ – If set, overwrites
scim2_client.SCIMClient.raise_scim_errors.kwargs¶ – Additional parameters passed to the underlying HTTP request library.
- Returns:
A
Errorobject in case of error.A
ListResponse[resource_model]object in case of success.
- Usage:
Searching for all the resources filtering the ones with id contains with admin#from scim2_models import User, SearchRequest req = SearchRequest(filter='id co "john"') response = scim.search(search_request=search_request) # 'response' may be a ListResponse[User] or an Error object
Tip
Check the
SEARCH_REQUESTandSEARCH_RESPONSEcontexts to understand which value will excluded from the request payload, and which values are expected in the response payload.
- async bulk(bulk_request: BulkRequest[Resource] | dict[str, Any] | None = None, check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [200, 307, 308, 400, 401, 403, 404, 409, 413, 500, 501], raise_scim_errors: bool | None = None, **kwargs: Any) BulkResponse[Resource] | Error | dict[str, Any][source]#
Perform a POST bulk request to execute bulk operations, as defined in RFC7644 §3.7.
- Parameters:
bulk_request¶ – An object detailing the bulk request.
check_request_payload¶ – If set, overwrites
scim2_client.SCIMClient.check_request_payload. When it isFalse,bulk_requestis expected to be a dict that will be passed as-is in the request.check_response_payload¶ – If set, overwrites
scim2_client.SCIMClient.check_response_payload.expected_status_codes¶ – The list of expected status codes form the response. If
Noneany status code is accepted.raise_scim_errors¶ – If set, overwrites
scim2_client.SCIMClient.raise_scim_errors.kwargs¶ – Additional parameters passed to the underlying HTTP request library.
- Returns:
A
Errorobject in case of error.A
BulkResponseobject in case of success.
Important
A bulk job the server processed answers
200, whatever the outcome of the operations it carried, as defined at RFC7644 §3.7.3.raise_scim_errorsis about the bulk job itself, so failed operations raise nothing: theirstatusand theErrorobject theirresponsecarries are to be read one by one.- Usage:
Simultaneously creating a User resource and a Group resource containing the user#from scim2_models import ( BulkRequest, BulkOperation, Group, GroupMember, User, ) req = BulkRequest[User | Group]( operations=[ BulkOperation[User]( method="POST", path="/Users", bulk_id="qwerty", data=User(user_name="Alice"), ), BulkOperation[Group]( method="POST", path="/Groups", bulk_id="ytrewq", data=Group( display_name="Tour Guides", members=[GroupMember(type="User", value="bulkId:qwerty")], ), ), ] ) response = await scim.bulk(req) # 'response' may be a BulkResponse or an Error object for operation in response.operations: if operation.status >= 400: print(operation.bulk_id, operation.response.detail)
Tip
Check the
BULK_REQUESTandBULK_RESPONSEcontexts to understand which values will be excluded from the request payload, and which values are expected in the response payload.Tip
When the
ServiceProviderConfigis known, the request is checked against the bulk capabilities the server advertises, and a request the server would answer with a413is not sent.
- async delete(target: Resource | type[Resource] | ResourceType | str | _Me | None = None, id: str | Resource | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [204, 307, 308, 400, 401, 403, 404, 409, 412, 500, 501], raise_scim_errors: bool | None = None, **kwargs: Any) Error | dict[str, Any] | None[source]#
Perform a DELETE request, as defined in RFC7644 §3.6.
The resource to delete is designated by a resource type and an id, or by a
Resourceobject.- Parameters:
target¶ – A
ResourceType, or its name or id, or aResourcemodel, which goes to the resource type named after its schema. AResourceobject stands for both the resource type, read from itsmeta.resourceType, and the id.Mestands for the resource of the authenticated client.id¶ – The id of the resource to delete, or a
Resourceobject carrying it.check_response_payload¶ – If set, overwrites
scim2_client.SCIMClient.check_response_payload.expected_status_codes¶ – The list of expected status codes form the response. If
Noneany status code is accepted.raise_scim_errors¶ – If set, overwrites
scim2_client.SCIMClient.raise_scim_errors.kwargs¶ – Additional parameters passed to the underlying HTTP request library.
- Returns:
- Usage:
Deleting an User which id is foobar#from scim2_models import User response = await scim.delete(User, "foobar") user = await scim.query(User, "foobar") response = await scim.delete(user) # 'response' may be None, or an Error object
- async replace(target: ResourceT, resource: None = None, check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [200, 307, 308, 400, 401, 403, 404, 409, 412, 500, 501], raise_scim_errors: bool | None = None, **kwargs: Any) ResourceT | Error | dict[str, Any][source]#
- async replace(target: type[ResourceT], resource: ResourceT | dict[str, Any], check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [200, 307, 308, 400, 401, 403, 404, 409, 412, 500, 501], raise_scim_errors: bool | None = None, **kwargs: Any) ResourceT | Error | dict[str, Any]
- async replace(target: ResourceType | str | _Me | None, resource: ResourceT, check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [200, 307, 308, 400, 401, 403, 404, 409, 412, 500, 501], raise_scim_errors: bool | None = None, **kwargs: Any) ResourceT | Error | dict[str, Any]
- async replace(*, resource: ResourceT, check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [200, 307, 308, 400, 401, 403, 404, 409, 412, 500, 501], raise_scim_errors: bool | None = None, **kwargs: Any) ResourceT | Error | dict[str, Any]
- async replace(target: dict[str, Any] | ResourceType | str | _Me | None = None, resource: dict[str, Any] | None = None, check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [200, 307, 308, 400, 401, 403, 404, 409, 412, 500, 501], raise_scim_errors: bool | None = None, **kwargs: Any) Resource | Error | dict[str, Any]
Perform a PUT request to replace a resource, as defined in RFC7644 §3.5.1.
- Parameters:
target¶ – The
ResourceTypeof the resource, or its name or id, or aResourcemodel. When omitted, it is the one in themeta.resourceTypeof the resource, or else the one named after its schema. The resource itself may be passed here instead ofresource. WithMe, the resource of the authenticated client is replaced.resource¶ – The new resource. It must have an id, unless
targetisMe. If it is adict, it is read with the model passed astarget, or else with the model guessed from its schemas.check_request_payload¶ – If set, overwrites
scim2_client.SCIMClient.check_request_payload.check_response_payload¶ – If set, overwrites
scim2_client.SCIMClient.check_response_payload.expected_status_codes¶ – The list of expected status codes form the response. If
Noneany status code is accepted.raise_scim_errors¶ – If set, overwrites
scim2_client.SCIMClient.raise_scim_errors.kwargs¶ – Additional parameters passed to the underlying HTTP request library.
- Returns:
An
Errorobject in case of error.The updated object as returned by the server in case of success.
- Usage:
Replacement of a User resource#from scim2_models import User user = scim.query(User, "my-used-id") user.display_name = "Fancy New Name" updated_user = scim.replace(user)
Tip
Check the
RESOURCE_REPLACEMENT_REQUESTandRESOURCE_REPLACEMENT_RESPONSEcontexts to understand which value will excluded from the request payload, and which values are expected in the response payload.
- async modify(target: ResourceT | type[ResourceT] | ResourceType | str | _Me | None = None, id: str | ResourceT | PatchOp[TypeVar] | dict[str, Any] | None = None, patch_op: PatchOp[TypeVar] | dict[str, Any] | None = None, check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [200, 204, 307, 308, 400, 401, 403, 404, 409, 412, 500, 501], raise_scim_errors: bool | None = None, **kwargs: Any) ResourceT | Error | dict[str, Any] | None[source]#
Perform a PATCH request to modify a resource, as defined in RFC7644 §3.5.2.
The resource to modify is designated by a resource type and an id, or by a
Resourceobject.- Parameters:
target¶ – A
ResourceType, or its name or id, or aResourcemodel, which goes to the resource type named after its schema. AResourceobject stands for both the resource type, read from itsmeta.resourceType, and the id.Mestands for the resource of the authenticated client.id¶ – The id of the resource to modify, or a
Resourceobject carrying it. Whentargetis aResourceobject, the patch operation may be passed here.patch_op¶ – The
PatchOpobject describing the modifications. Must be parameterized with the model of the resource (e.g.,PatchOp[User]for aUser).check_request_payload¶ – If set, overwrites
scim2_client.SCIMClient.check_request_payload.check_response_payload¶ – If set, overwrites
scim2_client.SCIMClient.check_response_payload.expected_status_codes¶ – The list of expected status codes form the response. If
Noneany status code is accepted.raise_scim_errors¶ – If set, overwrites
scim2_client.SCIMClient.raise_scim_errors.kwargs¶ – Additional parameters passed to the underlying HTTP request library.
- Returns:
- Usage:
Modification of a User resource#from scim2_models import User, PatchOp, PatchOperation operation = PatchOperation( op="replace", path="displayName", value="New Display Name" ) patch_op = PatchOp[User](operations=[operation]) response = await scim.modify(User, "my-user-id", patch_op) user = await scim.query(User, "my-user-id") response = await scim.modify(user, patch_op) # 'response' may be a User, None, or an Error object
Tip
Check the
RESOURCE_PATCH_REQUESTandRESOURCE_PATCH_RESPONSEcontexts to understand which value will excluded from the request payload, and which values are expected in the response payload.
- async discover(schemas: bool = True, resource_types: bool = True, service_provider_config: bool = True) None[source]#
Dynamically discover the server configuration objects.
Only what the
providerdoes not describe yet is queried, so what the client was given takes precedence over what the server publishes.- Parameters:
resource_types¶ – Whether to discover the
ResourceTypeendpoint.service_provider_config¶ – Whether to discover the
ServiceProviderConfigendpoint.
- Raises:
InvalidServiceDescriptionException – When the objects the server publishes do not describe a coherent service.
- async request(method: str, url: str, **kwargs: Any) RawResponse[source]#
Send a request to the server, without any SCIM processing.
Neither the request nor the response is checked, so this is fitted to observe how the server behaves, for instance with an unsupported HTTP method.
- Parameters:
- Returns:
The response of the underlying HTTP request library.
- Raises:
RequestNetworkException – When the request cannot be sent.
- Usage:
Checking that the/Schemasendpoint refusesDELETE#response = await scim.request("DELETE", "/Schemas") assert response.status_code == 405
- scim2_client.Me#
The resource of the authenticated client, reached under
/Me(RFC 7644 §3.11).Pass it as the target of
query,create,replace,modifyordelete.