Pydantic SCIM
Pydantic-SCIM provides Pydantic models that strictly adhere to the SCIM (System for Cross-domain Identity Management) specification. It allows developers to define, validate, and serialize SCIM resources like Users and Groups, simplifying integration with SCIM-compliant identity providers. The library currently supports Pydantic v1.x.
Common errors
-
TypeError: 'TypeAliasType' object is not subscriptable
cause Attempting to use pydantic-scim with Pydantic v2. This error specifically arises because Pydantic v2 changed how type aliases are handled.fixDowngrade Pydantic to version 1.x: `pip uninstall pydantic && pip install 'pydantic<2.0.0'`. -
pydantic.error_wrappers.ValidationError: 1 validation error for User\nschemas\n field required (type=value_error.missing)
cause A required SCIM field (in this case, `schemas`) was omitted when instantiating a SCIM model, or an invalid value was provided.fixEnsure all mandatory SCIM attributes are provided and correctly typed. For `User`, the `schemas` field is always required and should include `"urn:ietf:params:scim:schemas:core:2.0:User"`. -
AttributeError: 'User' object has no attribute 'model_dump_json'
cause Attempting to use a Pydantic v2 method (`model_dump_json`) on a model defined with Pydantic v1.fixFor Pydantic v1 models, use `user.json()` to serialize to JSON, or `user.dict()` to get a dictionary representation.
Warnings
- breaking pydantic-scim is only compatible with Pydantic v1.x. Installing it with Pydantic v2.x will lead to import errors, validation failures, or unexpected behavior.
- gotcha SCIM schemas are very strict. Missing required fields (e.g., `schemas`, `userName` for User) or providing incorrect data types will result in Pydantic `ValidationError`.
- gotcha SCIM attribute names are case-sensitive and must match the specification exactly (e.g., `userName`, `givenName`, `familyName`). Python's convention often uses `snake_case`, but SCIM uses `camelCase`.
Install
-
pip install pydantic-scim
Imports
- User
from pydantic_scim import User
- Group
from pydantic_scim import Group
- ListResponse
from pydantic_scim import ListResponse
Quickstart
from pydantic_scim import User
# Create a SCIM User object adhering to the SCIM Core Schema
user = User(
schemas=["urn:ietf:params:scim:schemas:core:2.0:User"],
userName="bjensen",
name={
"givenName": "Barbara",
"familyName": "Jensen"
},
emails=[
{
"value": "bjensen@example.com",
"type": "work",
"primary": True
}
],
active=True,
externalId="employee-id-123"
)
# Serialize the user object to JSON (using Pydantic v1 .json() method)
print(user.json(indent=2))