Skip to main content

Timeback OneRoster v1.2 client for rostering and gradebook APIs

Project description

timeback-oneroster

Python client for the OneRoster v1.2 API.

Installation

# pip
pip install timeback-oneroster

# uv (add to a project)
uv add timeback-oneroster

# uv (install into current environment)
uv pip install timeback-oneroster

Quick Start

from timeback_oneroster import OneRosterClient

async def main():
    client = OneRosterClient(
        env="staging",  # or "production"
        client_id="your-client-id",
        client_secret="your-client-secret",
    )

    # List all schools
    schools = await client.schools.list()
    for school in schools:
        print(school.name)

    # Get a specific user
    user = await client.users.get("user-sourced-id")
    print(f"{user.given_name} {user.family_name}")

    await client.close()

Client Structure

client = OneRosterClient(options)

# Rostering
client.users        # All users
client.students     # Students (filtered users)
client.teachers     # Teachers (filtered users)
client.classes      # Classes
client.schools      # Schools
# client.courses    # Coming soon
# client.enrollments # Coming soon
# client.terms      # Coming soon

Resource Operations

Each resource supports:

# List all items
users = await client.users.list()

# List with type-safe filtering (recommended)
active_teachers = await client.users.list(
    where={"status": "active", "role": "teacher"}
)

# With operators
teachers_or_aides = await client.users.list(
    where={"role": {"in_": ["teacher", "aide"]}}
)

# Not equal
non_deleted = await client.users.list(
    where={"status": {"ne": "deleted"}}
)

# Sorting
sorted_users = await client.users.list(
    where={"status": "active"},
    sort="familyName",
    order_by="asc",
)

# Legacy filter string (still supported)
active_users = await client.users.list(filter="status='active'")

# Get by sourcedId
user = await client.users.get("user-id")

# Create (where supported)
create_result = await client.classes.create({
    "title": "Math 101",
    "course": {"sourcedId": "course-id"},
    "school": {"sourcedId": "school-id"},
})
print(create_result.sourced_id_pairs.allocated_sourced_id)

# Update (where supported)
await client.classes.update("class-id", {"title": "Math 102"})

# Delete (where supported)
await client.classes.delete("class-id")

Nested Resources

# Schools
classes = await client.schools("school-id").classes()
students = await client.schools("school-id").students()
teachers = await client.schools("school-id").teachers()
courses = await client.schools("school-id").courses()

# Classes
students = await client.classes("class-id").students()
teachers = await client.classes("class-id").teachers()
enrollments = await client.classes("class-id").enrollments()

# Enroll a student
await client.classes("class-id").enroll({"sourcedId": "student-id", "role": "student"})

# Users
classes = await client.users("user-id").classes()
demographics = await client.users("user-id").demographics()

# Students / Teachers
classes = await client.students("student-id").classes()
classes = await client.teachers("teacher-id").classes()

Filtering

The client supports type-safe filtering with the where parameter:

# Simple equality
users = await client.users.list(where={"status": "active"})

# Multiple conditions (AND)
users = await client.users.list(
    where={"status": "active", "role": "teacher"}
)

# Operators
users = await client.users.list(where={"score": {"gte": 90}})        # >=
users = await client.users.list(where={"score": {"gt": 90}})         # >
users = await client.users.list(where={"score": {"lte": 90}})        # <=
users = await client.users.list(where={"score": {"lt": 90}})         # <
users = await client.users.list(where={"status": {"ne": "deleted"}}) # !=
users = await client.users.list(where={"email": {"contains": "@school.edu"}})  # substring

# Match any of multiple values (OR)
users = await client.users.list(
    where={"role": {"in_": ["teacher", "aide"]}}
)

# Exclude multiple values
users = await client.users.list(
    where={"status": {"not_in": ["deleted", "inactive"]}}
)

# Explicit OR across fields
users = await client.users.list(
    where={"OR": [{"role": "teacher"}, {"status": "active"}]}
)

Pagination

For large datasets, use streaming:

# Collect all users
all_users = await client.users.stream().to_list()

# With limits
first_100 = await client.users.stream(max_items=100).to_list()

# With filtering
active_users = await client.users.stream(
    where={"status": "active"}
).to_list()

# Get first item only
first_user = await client.users.stream().first()

Configuration

OneRosterClient(
    # Environment-based (recommended)
    env="production",  # or "staging"
    client_id="...",
    client_secret="...",

    # Or explicit URLs
    base_url="https://api.example.com",
    auth_url="https://auth.example.com/oauth2/token",
    client_id="...",
    client_secret="...",

    # Optional
    timeout=30.0,  # Request timeout in seconds
)

Environment Variables

If credentials are not provided explicitly, the client reads from:

  • ONEROSTER_CLIENT_ID
  • ONEROSTER_CLIENT_SECRET
  • ONEROSTER_BASE_URL (optional)
  • ONEROSTER_TOKEN_URL (optional)

Error Handling

from timeback_oneroster import OneRosterError, NotFoundError, AuthenticationError

try:
    user = await client.users.get("invalid-id")
except NotFoundError as e:
    print(f"User not found: {e.sourced_id}")
except AuthenticationError:
    print("Invalid credentials")
except OneRosterError as e:
    print(f"API error: {e}")

Async Context Manager

async with OneRosterClient(client_id="...", client_secret="...") as client:
    schools = await client.schools.list()
# Client is automatically closed

FastAPI Integration

from fastapi import FastAPI, Depends
from timeback_oneroster import OneRosterClient

app = FastAPI()

async def get_oneroster():
    client = OneRosterClient(
        env="production",
        client_id="...",
        client_secret="...",
    )
    try:
        yield client
    finally:
        await client.close()

@app.get("/schools")
async def list_schools(client: OneRosterClient = Depends(get_oneroster)):
    return await client.schools.list()

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

timeback_oneroster-0.1.3.tar.gz (40.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

timeback_oneroster-0.1.3-py3-none-any.whl (56.1 kB view details)

Uploaded Python 3

File details

Details for the file timeback_oneroster-0.1.3.tar.gz.

File metadata

  • Download URL: timeback_oneroster-0.1.3.tar.gz
  • Upload date:
  • Size: 40.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.27 {"installer":{"name":"uv","version":"0.9.27","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for timeback_oneroster-0.1.3.tar.gz
Algorithm Hash digest
SHA256 279cef57bb207fcd63cc323e48d7bbde7010f8242abe4a9b9871f260d6d70873
MD5 354a4e687d466cc9d89af737749d23f3
BLAKE2b-256 17c15474c67b1bf29e831e3c0421aac8ef1601c083ac14fffa748e76ef66b909

See more details on using hashes here.

File details

Details for the file timeback_oneroster-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: timeback_oneroster-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 56.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.27 {"installer":{"name":"uv","version":"0.9.27","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for timeback_oneroster-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 8f8e6b0fbc7f9610b3a957184bf85c2d1c89831836e5e6324589e9720cedde38
MD5 bfafbd0d9c7c689575953cca3c50d4d6
BLAKE2b-256 283e96f7d54a8671958d57be3810ef3135155319ab5a2d23e32340ecb60613a7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page