Skip to main content

Corfedo

Corfedo Python SDK

CI PyPI Python 3.11+ License: Apache-2.0 Documentation

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 corfedo.models import SendAiMessage

async with client.ai.stream(SendAiMessage(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

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.2

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

Source distribution (sdist)

Source distribution for corfedo 0.0.2
File Size Uploaded Provenance Actions
corfedo-0.0.2.tar.gz 99.4 kB With provenance Details for corfedo-0.0.2.tar.gz

Built distribution (wheel)

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

Total release size: 206.3 kB

Release files / corfedo-0.0.2.tar.gz

Download URL corfedo-0.0.2.tar.gz
Size 99.4 kB
Tags Source
SHA-256 checksum
How to use checksums
226706226f9707fd53047c539bb37b87b717628d9daca39147a3db2a63609933
BLAKE2b-256 checksum
How to use checksums
e91edc833316fc5d4308c292463fe16912128888df5b3a8857ae8eb1d0ec1d53
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 log

Release files / corfedo-0.0.2-py3-none-any.whl

Download URL corfedo-0.0.2-py3-none-any.whl
Size 106.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bb440165b1e656ed721bcb2ef60a53d6ebf7889686e6bd12d0f9b213585c83a8
BLAKE2b-256 checksum
How to use checksums
a2c27790b4a1ad4d5e117ae82624bdeb6333984179917a6981e98de7f0aa7532
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 log

Security for corfedo 0.0.2

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.

Select from 2 files

Attestation for corfedo-0.0.2.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 log

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.0.2 This release

2 release files Full 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