Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
7e6629f
refactor: restructure monorepo to organize packages by language
fahreddinozcan Dec 8, 2025
1fcce65
feat: add python sdk
fahreddinozcan Dec 8, 2025
f3a18a0
feat: add sync client
fahreddinozcan Dec 8, 2025
237bb99
finalize async-sync client seperation
fahreddinozcan Dec 8, 2025
124b612
fmt
fahreddinozcan Dec 8, 2025
da7a086
fmt
fahreddinozcan Dec 8, 2025
d930d81
fix client tests types
fahreddinozcan Dec 8, 2025
1260d08
docs: update import package name
fahreddinozcan Dec 8, 2025
10c1baf
docs: update import package name
fahreddinozcan Dec 8, 2025
2f3db99
refactor: restructure packages directory layout
fahreddinozcan Jan 6, 2026
a6a5fdf
feat: simplify sdk api
fahreddinozcan Jan 6, 2026
bdf8970
fix: update python workflow paths and skip changeset for python changes
fahreddinozcan Jan 6, 2026
4609891
fix: correct package directories and format python code
fahreddinozcan Jan 6, 2026
8814e26
chore: update pnpm lockfile
fahreddinozcan Jan 6, 2026
3f05fa2
fix: correct tsconfig extends path for mcp package
fahreddinozcan Jan 6, 2026
b3ec354
Merge branch 'master' of https://github.com/upstash/context7 into CTX…
fahreddinozcan Jan 6, 2026
bc2ad96
refactor: remove unused pagination headers from Python SDK
fahreddinozcan Jan 6, 2026
9137d7e
refactor: remove unused GetContextOptions and Context7ValidationError
fahreddinozcan Jan 6, 2026
5e6a9e5
Merge branch 'master' of https://github.com/upstash/context7 into CTX…
fahreddinozcan Jan 9, 2026
36da4b8
chore: update readme for python sdk
fahreddinozcan Jan 9, 2026
8e8ab4c
feat: update default response type to json from txt
fahreddinozcan Jan 9, 2026
22b9c04
docs: add python sdk docs
fahreddinozcan Jan 9, 2026
2482260
chore: remove changeset workflow
fahreddinozcan Jan 9, 2026
1140e59
fmt: python sdk
fahreddinozcan Jan 9, 2026
fd8a26a
Merge remote-tracking branch 'origin' into CTX7-907
enesgules Jan 19, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 0 additions & 47 deletions .github/workflows/changeset-check.yml

This file was deleted.

96 changes: 96 additions & 0 deletions .github/workflows/python-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
name: Python CI

on:
push:
branches: [main, master]
paths:
- "packages/python/**"
- ".github/workflows/python-ci.yml"
pull_request:
branches: [main, master]
paths:
- "packages/python/**"
- ".github/workflows/python-ci.yml"

defaults:
run:
working-directory: packages/python

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]

steps:
- uses: actions/checkout@v4

- name: Install uv
uses: astral-sh/setup-uv@v4
with:
version: "latest"

- name: Set up Python ${{ matrix.python-version }}
run: uv python install ${{ matrix.python-version }}

- name: Install dependencies
run: uv sync --all-packages

- name: Run linting
run: uv run ruff check .

- name: Run formatting check
run: uv run ruff format --check .

- name: Run type checking
run: uv run mypy sdk/src/context7

- name: Run tests
env:
CONTEXT7_API_KEY: ${{ secrets.CONTEXT7_API_KEY }}
run: uv run pytest sdk/tests -v --cov=context7 --cov-report=xml

build:
runs-on: ubuntu-latest
needs: test

steps:
- uses: actions/checkout@v4

- name: Install uv
uses: astral-sh/setup-uv@v4

- name: Build package
working-directory: packages/python/sdk
run: uv build

- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: python-sdk-dist
path: packages/python/sdk/dist/

publish:
runs-on: ubuntu-latest
needs: [test, build]
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
environment: pypi

steps:
- uses: actions/checkout@v4

- name: Install uv
uses: astral-sh/setup-uv@v4

- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: python-sdk-dist
path: packages/python/sdk/dist/

- name: Publish to PyPI
working-directory: packages/python/sdk
env:
UV_PUBLISH_TOKEN: ${{ secrets.PYPI_TOKEN }}
run: uv publish
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,20 @@ prompt.txt
reports
reports-old
src/test/questions*

# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
.venv/
venv/
ENV/
.mypy_cache/
.ruff_cache/
.pytest_cache/
*.egg-info/
dist/
build/
uv.lock
10 changes: 10 additions & 0 deletions docs/docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@
"pages": ["sdks/ts/commands/search-library", "sdks/ts/commands/get-context"]
}
]
},
{
"group": "Python",
"pages": [
"sdks/python/getting-started",
{
"group": "Commands",
"pages": ["sdks/python/commands/search-library", "sdks/python/commands/get-context"]
}
]
}
]
},
Expand Down
150 changes: 150 additions & 0 deletions docs/sdks/python/commands/get-context.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
---
title: "Get Context"
description: "Retrieve documentation context for a library"
---

# Get Context

Retrieve documentation context for a specific library. Returns documentation as a list of documentation objects (default) or as plain text.

## Arguments

<ParamField path="query" type="str" required>
The user's question or task (used for relevance ranking)
</ParamField>

<ParamField path="library_id" type="str" required>
The library identifier (e.g., `/facebook/react`)
</ParamField>

<ParamField path="type" type="Literal['json', 'txt']">
Format of the response
- `json`: List of Documentation objects (default)
- `txt`: Plain text format

Default: `"json"`
</ParamField>

## Response

The response type depends on the `type` parameter.

### JSON Format (`type="json"` or default)

Returns `list[Documentation]` - a list of documentation objects.

### Text Format (`type="txt"`)

Returns a `str` containing the documentation context ready to use in LLM prompts.

<ResponseField name="Documentation" type="object">
<Expandable title="properties">
<ResponseField name="title" type="str" required>
Title of the documentation snippet
</ResponseField>
<ResponseField name="content" type="str" required>
The documentation content (includes code blocks in markdown format)
</ResponseField>
<ResponseField name="source" type="str" required>
Source identifier for the snippet
</ResponseField>
</Expandable>
</ResponseField>

## Examples

<RequestExample>
```python JSON Format (Default)
from context7 import Context7

with Context7() as client:
docs = client.get_context(
"How do I use hooks?",
"/facebook/react"
)

for doc in docs:
print(doc.title)
print(doc.content)
print(doc.source)
```

```python Text Format
from context7 import Context7

with Context7() as client:
context = client.get_context(
"How do I use hooks?",
"/facebook/react",
type="txt"
)
print(context)
```

```python Async Usage
import asyncio
from context7 import Context7

async def main():
async with Context7() as client:
context = await client.get_context_async(
"How do I use hooks?",
"/facebook/react"
)
print(context)

asyncio.run(main())
```

```python Error Handling
from context7 import Context7, Context7Error

with Context7() as client:
try:
context = client.get_context(
"How to get started?",
"/invalid/library"
)
except Context7Error as e:
print(f"API Error: {e}")
```
</RequestExample>

## Use Cases

### Providing Context to LLMs

```python
from context7 import Context7

def get_docs_for_prompt(library: str, question: str) -> str:
with Context7() as client:
context = client.get_context(question, library, type="txt")

return f"""
Here is the relevant documentation:

{context}

User question: {question}
"""

prompt = get_docs_for_prompt("/facebook/react", "How do I use useEffect?")
```

### Processing Individual Snippets

```python
from context7 import Context7

with Context7() as client:
docs = client.get_context(
"How to create components?",
"/facebook/react"
)

for doc in docs:
print(f"Title: {doc.title}")
print(f"Source: {doc.source}")
print(f"Content length: {len(doc.content)} chars")
```
Loading
Loading