Skip to main content

42api

An object-oriented Python client for the 42 School API (api.intra.42.fr) that handles OAuth2 authentication, request pacing, and pagination for you, so you can work with typed resources instead of raw JSON and HTTP plumbing.

  • Sync and async — Client and AsyncClient share one codebase and the same interface.
  • Typed models — resources are Pydantic v2 models with IDE-friendly autocomplete.
  • Automatic rate limiting — requests are paced to stay under 42's limits; 429s are retried with backoff automatically.
  • Lazy pagination — iterate a query and it walks every page for you.

Install

uv add 42api
# or: pip install 42api

Usage

from intra42 import Client

with Client(client_id="...", client_secret="...") as client:
    user = client.users.get("jdoe")
    print(user.login, user.email)

    for user in client.users.filter(primary_campus_id=1).sort("-pool_year"):
        print(user.login)

Async is the same shape:

import asyncio
from intra42 import AsyncClient


async def main() -> None:
    async with AsyncClient(client_id="...", client_secret="...") as client:
        user = await client.users.get("jdoe")
        async for user in client.users.filter(primary_campus_id=1).sort("-pool_year"):
            print(user.login)


asyncio.run(main())

Fetched instances expose their nested resources directly — no need to build the scoped path yourself:

campus = client.campuses.get(1)
for event in campus.events:  # GET /campus/1/events
    print(event.name)

user = client.users.get("jdoe")
for cu in user.campus_users:  # GET /users/jdoe/campus_users
    print(cu.campus_id, cu.is_primary)

These (campus.events, campus.users, user.events, user.campus_users) are only available on instances fetched via a client — a manually constructed model raises a clear RuntimeError if accessed.

Get your client_id/client_secret by registering an app at https://profile.intra.42.fr/oauth/applications. This library uses the client credentials flow, so it accesses the API as your app rather than as a specific logged-in user.

Errors

All errors subclass intra42.FortyTwoAPIError, with subclasses for common HTTP statuses: AuthenticationError (401), PermissionDeniedError (403), NotFoundError (404), ValidationError (422), RateLimitError (429, only raised once the built-in retry budget is exhausted), ServerError (5xx), and NetworkError (connection/timeout failures).

Status

Early-stage: currently covers users, accreditations, campuses, campus_users, cursus, events, events_users, exams, locations, projects, and projects_users (exams, locations, and projects_users each include their graph analytics endpoint). More resources are added incrementally on top of the same client/model/query-builder pattern.

events_users also exposes the first write endpoints, subscribe / unsubscribe (register a user to an event and cancel it):

registration = client.events_users.subscribe(event_id=1234, user_id=42)
client.events_users.unsubscribe(registration.id)

These two calls need a resource-owner (user) token scoped on profile — the default app-level client-credentials token only grants the read endpoints. Build the client from a user token obtained via the authorization-code flow:

client = Client.from_access_token(user_access_token)  # AsyncClient too
client.events_users.subscribe(event_id=1234, user_id=42)

The remaining restricted-access APIs are not implemented currently.

Development

Uses uv for dependency management.

uv sync                                               # install dependencies
uv run pytest                                         # run tests
uv run ruff check . && uv run ruff format --check .   # lint
uv run mypy                                           # type check

The sync client (intra42._sync) is generated from the async client (intra42._async) via unasync — edit the async source and regenerate:

uv run python scripts/unasync_generate.py            # regenerate
uv run python scripts/unasync_generate.py --check    # verify no drift (CI)

License

MIT

Metadata

Release files for 42api 0.1.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for 42api 0.1.6
File Size Uploaded Provenance Actions
42api-0.1.6.tar.gz 94.9 kB Without provenance Details for 42api-0.1.6.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for 42api 0.1.6
File Interpreter ABI Platform Actions
42api-0.1.6-py3-none-any.whl Python 3 none any Details for 42api-0.1.6-py3-none-any.whl

Total release size: 142.9 kB

Release files / 42api-0.1.6.tar.gz

Download URL 42api-0.1.6.tar.gz
Size 94.9 kB
Tags Source
SHA-256 checksum
How to use checksums
5da40ed425e6c5436afad1bde9ebc9d232a6c1190aac1ed33c9ad58768489a8d
BLAKE2b-256 checksum
How to use checksums
7957df413913560d8423d371b006ef5efbfde2d5e66bc382bfb8571f9f461b2b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / 42api-0.1.6-py3-none-any.whl

Download URL 42api-0.1.6-py3-none-any.whl
Size 48.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5f563c819b1c02ccd4f8b4ed26c5a2a47cf1d79193a09db9b25fa3e486dcaea1
BLAKE2b-256 checksum
How to use checksums
64e54aedd508ea920d66a70ebbb5152368327c19c14fdf7baa677ed4ed05a6a7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for 42api 0.1.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.6 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page