Overview
The Mocra Python SDK wraps the Mocra REST API and handles authentication, serialization, and error handling for you. Package:mocra — requires Python 3.10+
Installation
Quick start
VideoObservabilityApi
The main client class. Instantiate it once with your API key and reuse it across requests.
Constructor parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
api_key | str | required | Your Mocra API key. See the Quickstart to get one. |
base_url | str | None | "https://api.mocra.io" | Override the API base URL. Useful for testing. |
timeout | float | 60.0 | Request timeout in seconds. |
http_client | httpx.Client | None | None | Bring your own pre-configured httpx.Client (e.g. with custom proxies or retry logic). |
score_video()
Analyzes a video against Mocra’s built-in criteria and any custom criteria you provide.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
video_url | str | required | Publicly accessible URL of the video to analyze. |
extra_criteria | list[ExtraCriterion] | [] | Additional custom criteria to evaluate. |
ignore_criteria | list[str | DefaultCriterion] | [] | Built-in criteria to exclude from the analysis. Accepts raw strings (e.g. "UNNATURAL PHYSICS") or DefaultCriterion enum values. |
Returns: ObserveResponse
| Field | Type | Description |
|---|---|---|
severity | float | Overall quality score from 1 (worst) to 100 (best). |
criteria | list[CriterionScore] | Per-criterion breakdown. Each item has name: str and score: float (1–100). |
ExtraCriterion
Defines a custom quality criterion to include in the analysis.
| Field | Type | Description |
|---|---|---|
criterion_name | str | Short label for the criterion. |
criterion_description | str | Full description of what the criterion checks. |
DefaultCriterion
An enum of the built-in criteria that Mocra evaluates by default. Pass one or more values to ignore_criteria to exclude them from the analysis.
| Value | String equivalent |
|---|---|
DefaultCriterion.UNNATURAL_PHYSICS | "UNNATURAL PHYSICS" |
DefaultCriterion.MORPHING | "MORPHING" |
DefaultCriterion.FLICKERING | "FLICKERING" |
DefaultCriterion.ARTIFACTING | "ARTIFACTING" |
DefaultCriterion.TEXT_ISSUES | "TEXT ISSUES" |
Error handling
The SDK raisesMocraError when the API returns a non-200 response, and httpx.HTTPError for network-level failures.
MocraError
| Attribute | Type | Description |
|---|---|---|
message | str | Human-readable error description from the API response. |
status_code | int | None | HTTP status code of the failed response. |
Context manager
UseVideoObservabilityApi as a context manager to ensure the underlying HTTP connection is closed when you’re done:
api.close() manually if you are not using the context manager.
