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 ScimProvider describing 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 provider instead. A collection of Resource models 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 provider instead. A collection of ResourceType that will be used to guess the server endpoints associated with the resources.

  • service_provider_config – Deprecated, pass a provider instead. An instance of ServiceProviderConfig.

  • check_request_payload – If False, resource is 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 True and the server returned an Error object during a request, a SCIMException exception will be raised. If False the error object is returned. This value can be overwritten in methods.

Note

ResourceType, Schema and scim2_models.ServiceProviderConfig are 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. 200 is the only success code, as the individual operation results are carried by the response payload. 413 is answered when the request exceeds the limits the server advertises, as defined at RFC7644 §3.7.4. 412 is 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 ScimProvider describing the server.

property resource_models: tuple[type[Resource], ...]#

Deprecated, read provider instead.

property resource_types: tuple[ResourceType, ...] | None#

Deprecated, read provider instead.

property service_provider_config: ServiceProviderConfig | None#

Deprecated, read provider instead.

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 endpoint a request is sent to.

Parameters:

target – A ResourceType, or its name or id. A Resource model goes to the resource type named after its schema. A Resource object goes to the resource type of its meta.resourceType. Me goes to /Me.

register_naive_resource_types() → None[source]#

Register a naive ResourceType for each model the provider describes.

This fills the ResourceType with generic values. The endpoint is the resource name with a s suffix. For instance, the User will have a /Users endpoint.

Deprecated since version 0.9: A ScimProvider given no ResourceType builds 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, the Error the server may have returned, the status code and the payload are examined in that order.

Parameters:
  • payload – The decoded body of the response, or None when 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, None for any.

  • expected_types – The resource types the operation may return.

  • check_response_payload – Overrides check_response_payload for this response.

  • raise_scim_errors – Overrides raise_scim_errors for this response.

  • scim_ctx – The Context the payload is validated under.

  • 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_discovery instead. 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 ResourceType to create the resource in, or its name or id, or a Resource model. When omitted, it is the one named after the schema of the resource. The resource itself may be passed here instead of resource. With Me, 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 as target, 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 None any status code is accepted.

  • raise_scim_errors – If set, overwrites raise_scim_errors.

  • kwargs – Additional parameters passed to the underlying HTTP request library.

Returns:

  • An Error object in case of error.

  • The created object as returned by the server in case of success and check_response_payload is True.

  • The created object payload as returned by the server in case of success and check_response_payload is False.

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_REQUEST and RESOURCE_CREATION_RESPONSE contexts 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.

  • If id is not None, the resource with this id is read.

  • If id is None, all the resources of the resource type are listed.

  • If target is None, all the available resources are listed.

When the server supports ETags and a Resource object carrying a version is passed, the read is conditional, and the object itself is returned when the server answers with a 304 Not Modified.

Parameters:
Returns:

  • A Error object in case of error.

  • A target type object in case of success when a single resource is designated, which is the target object itself when the server answers 304 Not Modified.

  • A ListResponse[target] object in case of success otherwise.

Note

Querying a ServiceProviderConfig will return a single object, and not a ListResponse.

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_REQUEST and RESOURCE_QUERY_RESPONSE contexts 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:
Returns:

  • A Error object 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_REQUEST and SEARCH_RESPONSE contexts 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:
Returns:

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_errors is about the bulk job itself, so failed operations raise nothing: their status and the Error object their response carries 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_REQUEST and BULK_RESPONSE contexts to understand which values will be excluded from the request payload, and which values are expected in the response payload.

Tip

When the ServiceProviderConfig is known, the request is checked against the bulk capabilities the server advertises, and a request the server would answer with a 413 is 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 Resource object.

Parameters:
  • target – A ResourceType, or its name or id, or a Resource model, which goes to the resource type named after its schema. A Resource object stands for both the resource type, read from its meta.resourceType, and the id. Me stands for the resource of the authenticated client.

  • id – The id of the resource to delete, or a Resource object 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 None any 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 Error object in case of error.

  • None in case of success.

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:
Returns:

  • An Error object 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_REQUEST and RESOURCE_REPLACEMENT_RESPONSE contexts 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 Resource object.

Parameters:
  • target – A ResourceType, or its name or id, or a Resource model, which goes to the resource type named after its schema. A Resource object stands for both the resource type, read from its meta.resourceType, and the id. Me stands for the resource of the authenticated client.

  • id – The id of the resource to modify, or a Resource object carrying it. When target is a Resource object, the patch operation may be passed here.

  • patch_op – The PatchOp object describing the modifications. Must be parameterized with the model of the resource (e.g., PatchOp[User] for a User).

  • 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 None any 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 Error object in case of error.

  • The updated object as returned by the server in case of success if status code is 200.

  • None in case of success if status code is 204.

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_REQUEST and RESOURCE_PATCH_RESPONSE contexts 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 provider does not describe yet is queried, so what the client was given takes precedence over what the server publishes.

Parameters:
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:
  • method – The HTTP method.

  • url – The URL, relative to the SCIM server base URL.

  • kwargs – Additional parameters passed to the underlying HTTP request library.

Returns:

The response of the underlying HTTP request library.

Raises:

RequestNetworkException – When the request cannot be sent.

Usage:

Checking that the /Schemas endpoint refuses DELETE#
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:
Returns:

  • An Error object in case of error.

  • The created object as returned by the server in case of success and check_response_payload is True.

  • The created object payload as returned by the server in case of success and check_response_payload is False.

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_REQUEST and RESOURCE_CREATION_RESPONSE contexts 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.

  • If id is not None, the resource with this id is read.

  • If id is None, all the resources of the resource type are listed.

  • If target is None, all the available resources are listed.

When the server supports ETags and a Resource object carrying a version is passed, the read is conditional, and the object itself is returned when the server answers with a 304 Not Modified.

Parameters:
Returns:

  • A Error object in case of error.

  • A target type object in case of success when a single resource is designated, which is the target object itself when the server answers 304 Not Modified.

  • A ListResponse[target] object in case of success otherwise.

Note

Querying a ServiceProviderConfig will return a single object, and not a ListResponse.

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_REQUEST and RESOURCE_QUERY_RESPONSE contexts 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:
Returns:

  • A Error object 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_REQUEST and SEARCH_RESPONSE contexts 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:
Returns:

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_errors is about the bulk job itself, so failed operations raise nothing: their status and the Error object their response carries 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_REQUEST and BULK_RESPONSE contexts to understand which values will be excluded from the request payload, and which values are expected in the response payload.

Tip

When the ServiceProviderConfig is known, the request is checked against the bulk capabilities the server advertises, and a request the server would answer with a 413 is 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 Resource object.

Parameters:
  • target – A ResourceType, or its name or id, or a Resource model, which goes to the resource type named after its schema. A Resource object stands for both the resource type, read from its meta.resourceType, and the id. Me stands for the resource of the authenticated client.

  • id – The id of the resource to delete, or a Resource object 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 None any 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 Error object in case of error.

  • None in case of success.

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:
Returns:

  • An Error object 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_REQUEST and RESOURCE_REPLACEMENT_RESPONSE contexts 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 Resource object.

Parameters:
  • target – A ResourceType, or its name or id, or a Resource model, which goes to the resource type named after its schema. A Resource object stands for both the resource type, read from its meta.resourceType, and the id. Me stands for the resource of the authenticated client.

  • id – The id of the resource to modify, or a Resource object carrying it. When target is a Resource object, the patch operation may be passed here.

  • patch_op – The PatchOp object describing the modifications. Must be parameterized with the model of the resource (e.g., PatchOp[User] for a User).

  • 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 None any 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 Error object in case of error.

  • The updated object as returned by the server in case of success if status code is 200.

  • None in case of success if status code is 204.

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_REQUEST and RESOURCE_PATCH_RESPONSE contexts 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 provider does not describe yet is queried, so what the client was given takes precedence over what the server publishes.

Parameters:
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:
  • method – The HTTP method.

  • url – The URL, relative to the SCIM server base URL.

  • kwargs – Additional parameters passed to the underlying HTTP request library.

Returns:

The response of the underlying HTTP request library.

Raises:

RequestNetworkException – When the request cannot be sent.

Usage:

Checking that the /Schemas endpoint refuses DELETE#
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, modify or delete.

class scim2_client.client.ResponseHeaders(*args, **kwargs)[source]#

The headers of a response, looked up by case-insensitive names.

class scim2_client.client.RawResponse(*args, **kwargs)[source]#

A response as returned by the HTTP library of an engine.

property headers: ResponseHeaders#

The HTTP headers.

property status_code: int#

The HTTP status code.

property text: str#

The body, decoded as text.