Skip to main content

grad_pylib

Graduate College Python common library for web application APIs and other related projects.

Additional documentation:

Authentication

Applications authenticate with Azure AD through grad_pylib.core.auth. A few things are worth knowing before deploying a service that uses it.

Set ENVIRONMENT

ENVIRONMENT defaults to production (fail-closed). Set it explicitly to development, local, or test for local development and automated tests; only those values are treated as development environments. Outside those, the .env file is not loaded at all, so a stray dotenv file in the working directory cannot override production configuration.

The development API key is a full bypass

When ENABLE_DEV_API_KEY is turned on, a request carrying the Api-Key header authenticates as any role it asks for through the Api-Role header, with no token involved. This is intentional: arbitrary impersonation is needed for local development and automated end-to-end tests. It is guarded as follows:

  • ENABLE_DEV_API_KEY must be explicitly enabled, and settings validation refuses it outside a development environment.
  • The request must arrive from a loopback address. Forwarding headers such as X-Forwarded-For are ignored, so a leaked key is not remotely exploitable.
  • A request that presents Api-Key when the bypass is unavailable, or presents the wrong key, is rejected with a 401 and audited. It never falls through to Azure AD authentication.

Validating the requested role against the application's roles is the consuming project's responsibility, inside its api_key_user_builder.

Audit logging

Every authentication decision is emitted to the grad_pylib.audit.auth logger as a structured event: auth.access.granted, auth.access.denied, auth.failed, auth.token.rejected, auth.api_key.bypass and auth.roles.overridden. Records include the subject, policy, mechanism, effective roles, client address and request path. Note that override_loader is a privilege-granting hook, and any override that changes the effective roles is logged.

Identities

Only illinois.edu and uillinois.edu UPNs are accepted; other domains and tokens without a UPN claim are rejected with a 401. Only the application's own user object is stored on request.state.user, so the raw access token is not left where an error handler or APM integration could serialize it.

The library's contract for a user is the AuthUser protocol — a read-only effective_roles sequence. An application can satisfy it with any immutable type it likes; BaseUser is a ready-made implementation, not a required base class. Its fields are stored exactly as declared (tuples, and a read-only attribute mapping), so untrusted values are normalized where they enter the application, with parse_roles() and parse_distinct_strings(). Users are immutable — use with_roles_override() or dataclasses.replace() to derive a modified user.

Authorization configuration

AuthConfiguration is a frozen pydantic model that is validated once, at startup:

  • policy_roles entries must name roles from valid_roles. They are matched case-insensitively and stored in the canonical casing, so a typo or a casing mismatch is a startup error rather than an endpoint that silently never grants access.
  • A policy with no roles is rejected at construction rather than when its dependency is built.
  • The policy mapping and its role sets are deep-frozen, so a caller holding a reference to what it passed in cannot change authorization decisions at runtime.

A policy grants access when the user holds any of its roles.

Metadata

Release files for grad-pylib 8.0.4

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

Source distribution (sdist)

Source distribution for grad-pylib 8.0.4
File Size Uploaded Provenance Actions
grad_pylib-8.0.4.tar.gz 250.9 kB Without provenance Details for grad_pylib-8.0.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for grad-pylib 8.0.4
File Interpreter ABI Platform Actions
grad_pylib-8.0.4-py3-none-any.whl Python 3 none any Details for grad_pylib-8.0.4-py3-none-any.whl

Total release size: 395.6 kB

Release files / grad_pylib-8.0.4.tar.gz

Download URL grad_pylib-8.0.4.tar.gz
Size 250.9 kB
Tags Source
SHA-256 checksum
How to use checksums
5fceba8b7d819d8cf9b96ed851e5fadbe9b83ef622b4d0b4253d46a09228d1b9
BLAKE2b-256 checksum
How to use checksums
f5fa4b8118d07409ea5cc0c28feca77e5766f6e6f7c2ac8cdec478f0b6e837ad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","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}

Release files / grad_pylib-8.0.4-py3-none-any.whl

Download URL grad_pylib-8.0.4-py3-none-any.whl
Size 144.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
02f499e225dc81e3b58edc936a60b4fec4ca4744fd73cd6bea579af9baf5524d
BLAKE2b-256 checksum
How to use checksums
e4edc645fb3dac1a4f0e103c95ef5d1ee98f761c8c7121669dcfb9c3d5efa35d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","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}

Security for grad-pylib 8.0.4

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

8.0.4 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