Python

Get Started

Use the official context212-sdk client in Python apps.

context212-sdk is the official Python client for Context212. It ships typed endpoint functions (sync and async) plus attrs request and response models.

Install

pip install context212-sdk
# or: uv add context212-sdk

Configure the client

Create an AuthenticatedClient with the base URL and your API key:

import os

from context212_sdk import AuthenticatedClient

client = AuthenticatedClient(
    base_url="https://api.context212.com",
    token=os.environ["CONTEXT212_API_KEY"],
)

The base URL defaults to your deployment — https://api.context212.com for the hosted API.

See Authentication for how API keys work.

Call an endpoint

Each endpoint lives under context212_sdk.api and comes in four variants: sync, sync_detailed, asyncio, and asyncio_detailed. Requests are attrs models.

from context212_sdk.api.ask import ask
from context212_sdk.api.search import search
from context212_sdk.models import AskRequest, SearchRequest

answer = ask.sync(
    client=client,
    body=AskRequest(
        query="What is the vacation policy?",
        workspace_id=[42],
        max_results=5,
    ),
)
print(answer.answer)

hits = search.sync(
    client=client,
    body=SearchRequest(query="vacation policy", workspace_id=[42], max_results=3),
)
for result in hits.results:
    print(result.content[:120])

The plain sync / asyncio variants return the parsed model; the _detailed variants return a Response with status_code, headers, and parsed.

Common methods

MethodHTTPPurpose
ask.sync / ask.asyncioPOST /api/v1/askGrounded Q&A over your corpus
search.sync / search.asyncioPOST /api/v1/searchHybrid / vision search
files_create / files_list / files_retrieveFiles APIUpload and inspect documents
parse / parse_retrievePOST / GET /api/v1/parseDocument parse jobs
extract / extract_retrievePOST / GET /api/v1/extractStructured extraction jobs
list_workspaces / create_workspace / get_workspaceWorkspacesScope and manage workspaces
tags_list / add_tags / delete_tagsTagsOrganize content with tags
ontology_templates_list / ontology_concepts_create / ontology_relations_createOntologyConcepts, relations, and graph filters

For every parameter and response field, see the API reference.

On this page