Reference

class scim2_client.engines.httpx.SyncSCIMClient(client: Client, *args, **kwargs)[source]

Perform SCIM requests over the network and validate responses.

Parameters:
  • client – A httpx.Client instance that will be used to send requests.

  • resource_models – A tuple of Resource types 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.

  • 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.

  • raise_scim_errors – If True and the server returned an Error object during a request, a SCIMResponseErrorObject exception will be raised. If False the error object is returned. This value can be overwritten in methods.

create(resource: AnyResource | dict, 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) AnyResource | Error | dict[source]

Perform a POST request to create, as defined in RFC7644 §3.3.

Parameters:
  • resource – The resource to create If is a dict, the resource type will be guessed from the schema.

  • 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(resource_model: type[Resource] | None = None, id: str | None = None, query_parameters: ResponseParameters | dict | None = None, check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [200, 400, 307, 308, 401, 403, 404, 500], raise_scim_errors: bool | None = None, search_request: ResponseParameters | dict | None = None, **kwargs) Resource | ListResponse[Resource] | Error | dict[source]

Perform a GET request to read resources, as defined in RFC7644 §3.4.2.

  • If id is not None, the resource with the exact id will be reached.

  • If id is None, all the resources with the given type will be reached.

Parameters:
Returns:

  • A Error object in case of error.

  • A resource_model object in case of success if id is not None

  • A ListResponse[resource_model] object in case of success if id is None

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' 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(search_request: SearchRequest | 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) Resource | ListResponse[Resource] | Error | dict[source]

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.

delete(resource_model: type[Resource], id: str, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [204, 307, 308, 400, 401, 403, 404, 412, 500, 501], raise_scim_errors: bool | None = None, **kwargs) Error | dict | None[source]

Perform a DELETE request to create, as defined in RFC7644 §3.6.

Parameters:
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, SearchRequest

response = scim.delete(User, "foobar")
# 'response' may be None, or an Error object
replace(resource: AnyResource | dict, 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) AnyResource | Error | dict[source]

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(resource_model: type[ResourceT], id: str, patch_op: PatchOp[TypeVar] | dict, 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) ResourceT | Error | dict | None[source]

Perform a PATCH request to modify a resource, as defined in RFC7644 §3.5.2.

Parameters:
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)
# '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.

class scim2_client.engines.httpx.AsyncSCIMClient(client: AsyncClient, *args, **kwargs)[source]

Perform SCIM requests over the network and validate responses.

Parameters:
  • client – A httpx.AsyncClient instance that will be used to send requests.

  • resource_models – A tuple of Resource types 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.

  • 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.

  • raise_scim_errors – If True and the server returned an Error object during a request, a SCIMResponseErrorObject exception will be raised. If False the error object is returned. This value can be overwritten in methods.

async create(resource: AnyResource | dict, 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) AnyResource | Error | dict[source]

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(resource_model: type[Resource] | None = None, id: str | None = None, query_parameters: ResponseParameters | dict | None = None, check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [200, 400, 307, 308, 401, 403, 404, 500], raise_scim_errors: bool | None = None, search_request: ResponseParameters | dict | None = None, **kwargs) Resource | ListResponse[Resource] | Error | dict[source]

Perform a GET request to read resources, as defined in RFC7644 §3.4.2.

  • If id is not None, the resource with the exact id will be reached.

  • If id is None, all the resources with the given type will be reached.

Parameters:
Returns:

  • A Error object in case of error.

  • A resource_model object in case of success if id is not None

  • A ListResponse[resource_model] object in case of success if id is None

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' 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(search_request: SearchRequest | 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) Resource | ListResponse[Resource] | Error | dict[source]

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 delete(resource_model: type[Resource], id: str, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [204, 307, 308, 400, 401, 403, 404, 412, 500, 501], raise_scim_errors: bool | None = None, **kwargs) Error | dict | None[source]

Perform a DELETE request to create, as defined in RFC7644 §3.6.

Parameters:
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, SearchRequest

response = scim.delete(User, "foobar")
# 'response' may be None, or an Error object
async replace(resource: AnyResource | dict, 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) AnyResource | Error | dict[source]

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(resource_model: type[ResourceT], id: str, patch_op: PatchOp[TypeVar] | dict, 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) ResourceT | Error | dict | None[source]

Perform a PATCH request to modify a resource, as defined in RFC7644 §3.5.2.

Parameters:
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)
# '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.

class scim2_client.engines.werkzeug.TestSCIMClient(client: Client, environ: dict | None = None, scim_prefix: str = '', *args, **kwargs)[source]

A client based on Werkzeug test Client for application development purposes.

This is helpful for developers of SCIM servers. This client avoids to perform real HTTP requests and directly execute the server code instead. This allows to dynamically catch the exceptions if something gets wrong.

Parameters:
  • client – An optional custom Werkzeug test Client. If None a default client is initialized.

  • scim_prefix – The scim root endpoint in the application.

  • environ – Additional parameters that will be passed to every request.

  • resource_models – A tuple of Resource types 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.

  • 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.

  • raise_scim_errors – If True and the server returned an Error object during a request, a SCIMResponseErrorObject exception will be raised. If False the error object is returned. This value can be overwritten in methods.

from scim2_client.engines.werkzeug import TestSCIMClient
from scim2_models import User, Group
from werkzeug.test import Client

scim_provider = myapp.create_app()
testclient = TestSCIMClient(
    app=Client(scim_provider),
    environ={"base_url": "/scim/v2"},
    resource_models=(User, Group),
)

request_user = User(user_name="foo", display_name="bar")
response_user = scim_client.create(request_user)
assert response_user.user_name == "foo"
create(resource: AnyResource | dict, 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) AnyResource | Error | dict[source]

Perform a POST request to create, as defined in RFC7644 §3.3.

Parameters:
  • resource – The resource to create If is a dict, the resource type will be guessed from the schema.

  • 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(resource_model: type[Resource] | None = None, id: str | None = None, query_parameters: ResponseParameters | dict | None = None, check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [200, 400, 307, 308, 401, 403, 404, 500], raise_scim_errors: bool | None = None, search_request: ResponseParameters | dict | None = None, **kwargs) Resource | ListResponse[Resource] | Error | dict[source]

Perform a GET request to read resources, as defined in RFC7644 §3.4.2.

  • If id is not None, the resource with the exact id will be reached.

  • If id is None, all the resources with the given type will be reached.

Parameters:
Returns:

  • A Error object in case of error.

  • A resource_model object in case of success if id is not None

  • A ListResponse[resource_model] object in case of success if id is None

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' 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(search_request: SearchRequest | 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) Resource | ListResponse[Resource] | Error | dict[source]

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.

delete(resource_model: type[Resource], id: str, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [204, 307, 308, 400, 401, 403, 404, 412, 500, 501], raise_scim_errors: bool | None = None, **kwargs) Error | dict | None[source]

Perform a DELETE request to create, as defined in RFC7644 §3.6.

Parameters:
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, SearchRequest

response = scim.delete(User, "foobar")
# 'response' may be None, or an Error object
replace(resource: AnyResource | dict, 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) AnyResource | Error | dict[source]

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(resource_model: type[ResourceT], id: str, patch_op: PatchOp[TypeVar] | dict, 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) ResourceT | Error | dict | None[source]

Perform a PATCH request to modify a resource, as defined in RFC7644 §3.5.2.

Parameters:
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)
# '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.

class scim2_client.SCIMClient(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:
  • resource_models – 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 – A collection of ResourceType that will be used to guess the server endpoints associated with the resources.

  • service_provider_config – 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 SCIMResponseErrorObject 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, 400, 307, 308, 401, 403, 404, 500]

Resource querying HTTP codes.

As defined at RFC7644 §3.4.2 and RFC7644 §3.12.

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.

DELETION_RESPONSE_STATUS_CODES: list[int] = [204, 307, 308, 400, 401, 403, 404, 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.

get_resource_model(name: str) type[Resource] | None[source]

Get a registered model by its name or its schema.

resource_endpoint(resource_model: type[Resource] | None) str[source]

Find the endpoint associated with a given Resource.

Internally, it looks if any resource_type of the client matches the resource_model by comparing schemas.

register_naive_resource_types()[source]

Register a naive ResourceType for each resource_model.

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.

build_resource_models(resource_types: Collection[ResourceType], schemas: Collection[Schema]) tuple[type[Resource]][source]

Build models from server objects.

class scim2_client.BaseSyncSCIMClient(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(resource: AnyResource | dict, 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) AnyResource | Error | dict[source]

Perform a POST request to create, as defined in RFC7644 §3.3.

Parameters:
  • resource – The resource to create If is a dict, the resource type will be guessed from the schema.

  • 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(resource_model: type[Resource] | None = None, id: str | None = None, query_parameters: ResponseParameters | dict | None = None, check_request_payload: bool | None = None, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [200, 400, 307, 308, 401, 403, 404, 500], raise_scim_errors: bool | None = None, search_request: ResponseParameters | dict | None = None, **kwargs) Resource | ListResponse[Resource] | Error | dict[source]

Perform a GET request to read resources, as defined in RFC7644 §3.4.2.

  • If id is not None, the resource with the exact id will be reached.

  • If id is None, all the resources with the given type will be reached.

Parameters:
Returns:

  • A Error object in case of error.

  • A resource_model object in case of success if id is not None

  • A ListResponse[resource_model] object in case of success if id is None

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' 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(search_request: SearchRequest | 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) Resource | ListResponse[Resource] | Error | dict[source]

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.

delete(resource_model: type, id: str, check_response_payload: bool | None = None, expected_status_codes: list[int] | None = [204, 307, 308, 400, 401, 403, 404, 412, 500, 501], raise_scim_errors: bool | None = None, **kwargs) Error | dict | None[source]

Perform a DELETE request to create, as defined in RFC7644 §3.6.

Parameters:
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, SearchRequest

response = scim.delete(User, "foobar")
# 'response' may be None, or an Error object
replace(resource: AnyResource | dict, 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) AnyResource | Error | dict[source]

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(resource_model: type[ResourceT], id: str, patch_op: PatchOp[TypeVar] | dict, 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) ResourceT | Error | dict | None[source]

Perform a PATCH request to modify a resource, as defined in RFC7644 §3.5.2.

Parameters:
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)
# '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=True, resource_types=True, service_provider_config=True)[source]

Dynamically discover the server configuration objects.

Parameters:
exception scim2_client.SCIMClientError(message: str, source: Any = None, *args: Any, **kwargs: Any)[source]

Base exception for scim2-client.

Parameters:
  • message – The exception reason.

  • source – The request payload or the response object that have caused the exception.

exception scim2_client.SCIMRequestError(message: str, source: Any = None, *args: Any, **kwargs: Any)[source]

Base exception for errors happening during request payload building.

exception scim2_client.SCIMResponseError(message: str, source: Any = None, *args: Any, **kwargs: Any)[source]

Base exception for errors happening during response payload validation.

exception scim2_client.SCIMResponseErrorObject(error: Error, *args: Any, **kwargs: Any)[source]

The server response returned a scim2_models.Error object.

Those errors are only raised when the raise_scim_errors parameter is True.

Parameters:

error – The Error object returned by the server.

to_error() Error[source]

Return the Error object returned by the server.

exception scim2_client.UnexpectedContentFormat(*args: Any, **kwargs: Any)[source]

Error raised when a server returned a response in a non-JSON format.

exception scim2_client.UnexpectedContentType(content_type: str, *args: Any, **kwargs: Any)[source]

Error raised when a server returned an unexpected Content-Type header in a response.

exception scim2_client.UnexpectedStatusCode(status_code: int, *args: Any, **kwargs: Any)[source]

Error raised when a server returned an unexpected status code for a given Context.

exception scim2_client.RequestPayloadValidationError(*args: Any, **kwargs: Any)[source]

Error raised when an invalid request payload has been passed to SCIMClient.

This error is raised when a pydantic.ValidationError has been caught while validating the client request payload. The original ValidationError is available with __cause__.

try:
    scim.create(
        {
            "schemas": ["urn:ietf:params:scim:schemas:core:2.0:User"],
            "active": "not-a-bool",
        }
    )
except RequestPayloadValidationError as exc:
    print("Original validation error cause", exc.__cause__)
exception scim2_client.RequestNetworkError(*args: Any, **kwargs: Any)[source]

Error raised when a network error happened during request.

This error is raised when a httpx.RequestError has been caught while performing a request. The original RequestError is available with __cause__.

exception scim2_client.ResponsePayloadValidationError(*args: Any, **kwargs: Any)[source]

Error raised when the server returned a payload that cannot be validated.

This error is raised when a pydantic.ValidationError has been caught while validating the server response payload. The original ValidationError is available with __cause__.

try:
    scim.query(User, "foobar")
except ResponsePayloadValidationError as exc:
    print("Original validation error cause", exc.__cause__)