Corfedo Python SDK
Search and read code across every repository your Corfedo workspace indexes, and ask Corfedo AI, from Python.
Corfedo is a self-hosted code search and AI service. It indexes the repositories you choose across your code hosts and answers searches and questions across them, for people and coding agents. This repository holds the async Python client for its public HTTP API, with optional LangChain and Pydantic AI integrations. Python 3.11 or later.
Install
pip install corfedo # client and framework-neutral tools
pip install 'corfedo[pydantic-ai]' # Pydantic AI toolset and model (corfedo.pydantic_ai)
pip install 'corfedo[langchain]' # LangChain tools and chat model (corfedo.langchain)
Quick start
import os
from corfedo import CorfedoClient
from corfedo.models import SearchCode
async with CorfedoClient.from_api_key_file(os.environ["CORFEDO_API_KEY_FILE"]) as client:
page = await client.search.search(SearchCode(query="where are search requests parsed"))
for result in page.results:
if result.kind == "file":
print(f"{result.repository} {result.path} @{result.revision}")
Bare words return the files that contain them, the most relevant first. Text in double quotes
matches exactly and a regular expression between slashes matches a pattern; uppercase AND, OR
and NOT combine them, and filters such as repo:, file: and lang: narrow the search:
SearchCode(query=r'"PlatformComposition" OR /Require\w+/ lang:csharp')
A person can sign in through the browser instead, for notebooks and local tools:
from corfedo import CorfedoAuthentication, CorfedoClient, HumanAuthenticationOptions
credentials = await CorfedoAuthentication.sign_in(
HumanAuthenticationOptions(api_base_uri="https://corfedo.example.com/")
)
async with CorfedoClient(credentials) as client:
...
With an AI framework, the application owns the model and the loop; Corfedo supplies the tools:
from pydantic_ai import Agent
from corfedo.pydantic_ai import CorfedoToolset
agent = Agent(model, toolsets=[CorfedoToolset(client)])
corfedo.langchain.get_corfedo_tools(client) returns LangChain structured tools for
create_agent, and corfedo.tools.CorfedoTools is the framework-neutral layer both adapters use.
corfedo.tools.INSTRUCTIONS is optional text for the agent's system prompt: it explains that a run
of * in a credential is masked by the index.
Tools return exact JSON text; tool failures are CorfedoToolErrors whose messages are safe to
show to the model. Other frameworks and provider SDKs use CorfedoTools directly: pass its
definitions to the model and its tool calls to execute.
Ask Corfedo AI
With an API key or sign-in that has the AI capability (corfedo:ai:invoke), client.ai sends
messages to Corfedo AI and streams its runs:
from uuid import uuid4
from corfedo.models import SendAiMessage
async with client.ai.stream(SendAiMessage(client_message_id=uuid4(), text="How are shards selected?")) as run:
async for event in run:
if event.type == "text.delta":
print(event.text, end="")
print(run.answer)
Streamed text is provisional; the answer comes from the run's completion. A dropped connection is recovered inside the call. Corfedo AI is also a chat model for LangChain and Pydantic AI. The conversation lives in Corfedo, so each call sends only the new message or the results of client tools:
from corfedo.langchain import ChatCorfedo
from corfedo.pydantic_ai import CorfedoModel, CorfedoModelSettings
answer = await ChatCorfedo(client=client).ainvoke("How are shards selected?")
agent = Agent(CorfedoModel(client), model_settings=CorfedoModelSettings(corfedo_tools=["search_code"]))
Sampling settings, system prompts and content other than text are rejected with
CorfedoUnsupportedInputError. The profile owns them.
More examples, including OpenAI Agents and Anthropic tool use, are in examples/.
Documentation
- Python SDK guide, LangChain and Pydantic AI on docs.corfedo.ai
- API keys and authentication
- Changelog
Related repositories
- corfedo-dotnet-sdk: .NET client with Microsoft.Extensions.AI integration
- corfedo-typescript-sdk: TypeScript client with Vercel AI SDK and LangChain.js integrations
- corfedo-install: installer for self-hosted Corfedo on Docker or Kubernetes
Development
uv sync --locked --all-extras
uv run python scripts/check_contract.py
uv run python scripts/check_version.py
uv run ruff check && uv run ruff format --check
uv run pyright
uv run pytest
uv build
uv run python tests/package/check_wheel.py
python3 scripts/prepare_package.py builds a preview package for testing before a release. Its version comes
from the sources, such as 0.0.1.dev0+s14275fd1c9c8e82a, so the same sources always give the same version. The wheel,
the sdist and manifest.json go to artifacts/packages/<version>/. See CONTRIBUTING.md.
License
Apache-2.0, see LICENSE and NOTICE. The bundled API contract has its own notice in contracts/NOTICE. Corfedo names, logos and brand assets are reserved and not covered by these licenses.
Metadata
Release files for corfedo 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| corfedo-0.0.1.tar.gz | 99.2 kB | With provenance | Details for corfedo-0.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| corfedo-0.0.1-py3-none-any.whl | Python 3 | none | any | Details for corfedo-0.0.1-py3-none-any.whl |
Total release size: 205.9 kB
Release files / corfedo-0.0.1.tar.gz
| Download URL | corfedo-0.0.1.tar.gz |
|---|---|
| Size | 99.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8a821b98a7582059e268219e6f9d462904bbf2fdee4a12242d9e79105f125958
|
|
BLAKE2b-256 checksum How to use checksums |
43d892bbb3e0aa66c2b08155c419869baf7b039163e1a2a397cfb7f32b81561c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.
Transparency logRelease files / corfedo-0.0.1-py3-none-any.whl
| Download URL | corfedo-0.0.1-py3-none-any.whl |
|---|---|
| Size | 106.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
46fe057261ea1512cd9bca0471b1b533bea0d3b7cabcb319491e8b8940e3c5b4
|
|
BLAKE2b-256 checksum How to use checksums |
6c6fd2d1eae6446f58f4db67acd4e15a07087e5a179b7fd321592cda157d3de9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.
Transparency logSecurity for corfedo 0.0.1
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for corfedo-0.0.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.
Transparency logA 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.