SCIM2 Models

0.6.12 · active · verified Thu Apr 16

scim2-models is a Python library providing Pydantic models for SCIM (System for Cross-domain Identity Management) schemas, specifically RFC7643 and RFC7644. It facilitates the serialization and validation of SCIM2 payloads using native Python objects. The library includes features like context-aware validation and dynamic schema extensions, serving as a foundational block for building SCIM2 servers and clients. The current version is 0.6.12, and it is actively maintained with frequent releases.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to validate an existing SCIM User payload against the `User` model and how to construct a new `User` object directly. The `model_validate` method from Pydantic is used for parsing dictionary data, and `model_dump_json` for serialization.

from scim2_models.resources import User
from pydantic import ValidationError

user_data = {
    "schemas": ["urn:ietf:params:scim:schemas:core:2.0:User"],
    "userName": "bjensen@example.com",
    "id": "2819c223-7f76-453a-919d-413861904646",
    "name": {
        "givenName": "Babs",
        "familyName": "Jensen"
    },
    "emails": [
        {
            "value": "bjensen@example.com",
            "type": "work",
            "primary": True
        }
    ],
    "meta": {
        "resourceType": "User",
        "created": "2024-04-13T12:00:00Z",
        "lastModified": "2024-04-13T12:00:00Z",
        "location": "https://example.com/v2/Users/2819c223-7f76-453a-919d-413861904646"
    }
}

try:
    user = User.model_validate(user_data)
    print(f"Successfully validated user: {user.user_name}")
    print(f"User ID: {user.id}")
except ValidationError as e:
    print(f"Validation error: {e}")

# You can also create a user directly
new_user = User(
    userName="testuser",
    emails=[{"value": "test@example.com", "type": "work", "primary": True}]
)
print(f"Created new user: {new_user.model_dump_json(indent=2)}")

view raw JSON →