Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions .github/workflows/ecr-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ jobs:
id: build-push
uses: docker/build-push-action@v6
with:
context: packages/mcp
file: packages/mcp/Dockerfile
context: packages/ts/mcp
file: packages/ts/mcp/Dockerfile
platforms: linux/amd64
push: true
tags: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-mcp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
# Remove 'v' prefix if it exists
VERSION="${VERSION#v}"
else
VERSION=$(node -p "require('./packages/mcp/package.json').version")
VERSION=$(node -p "require('./packages/ts/mcp/package.json').version")
fi
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "Publishing version: $VERSION"
Expand Down
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/py/**"
- ".github/workflows/python-ci.yml"
pull_request:
branches: [main, master]
paths:
- "packages/py/**"
- ".github/workflows/python-ci.yml"

defaults:
run:
working-directory: packages/py

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/py/sdk
run: uv build

- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: python-sdk-dist
path: packages/py/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/py/sdk/dist/

- name: Publish to PyPI
working-directory: packages/py/sdk
env:
UV_PUBLISH_TOKEN: ${{ secrets.PYPI_TOKEN }}
run: uv publish
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ jobs:
if: steps.check-mcp.outputs.mcp_published == 'true'
run: |
VERSION="${{ steps.check-mcp.outputs.mcp_version }}"
sed -i "s/version: \"[0-9]*\.[0-9]*\.[0-9]*\"/version: \"$VERSION\"/" packages/mcp/src/index.ts
sed -i "s/version: \"[0-9]*\.[0-9]*\.[0-9]*\"/version: \"$VERSION\"/" packages/ts/mcp/src/index.ts
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add packages/mcp/src/index.ts
git add packages/ts/mcp/src/index.ts
git commit -m "chore: update MCP version in source to $VERSION" || true
git push || true

Expand Down
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
11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "1.0.0",
"description": "Context7 monorepo - Documentation tools and SDKs",
"workspaces": [
"packages/*"
"packages/ts/*"
],
"scripts": {
"build": "pnpm -r run build",
Expand All @@ -18,7 +18,14 @@
"format": "pnpm -r run format",
"format:check": "pnpm -r run format:check",
"release": "pnpm build && changeset publish",
"release:snapshot": "changeset version --snapshot canary && pnpm build && changeset publish --tag canary --no-git-tag"
"release:snapshot": "changeset version --snapshot canary && pnpm build && changeset publish --tag canary --no-git-tag",
"py:install": "cd packages/py && uv sync --all-packages",
"py:test": "cd packages/py && uv run pytest sdk/tests -v",
"py:lint": "cd packages/py && uv run ruff check .",
"py:format": "cd packages/py && uv run ruff format .",
"py:typecheck": "cd packages/py && uv run mypy sdk/src/context7",
"py:build": "cd packages/py/sdk && uv build",
"py:clean": "rm -rf packages/py/.venv packages/py/uv.lock packages/py/sdk/dist"
},
"repository": {
"type": "git",
Expand Down
1 change: 1 addition & 0 deletions packages/py/.python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.11
48 changes: 48 additions & 0 deletions packages/py/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
[project]
name = "context7-workspace"
version = "0.0.0"
description = "Context7 Python packages workspace"
requires-python = ">=3.9"
license = "MIT"

[tool.uv]
package = false

[tool.uv.workspace]
members = ["sdk"]

[tool.ruff]
line-length = 100
target-version = "py39"

[tool.ruff.lint]
select = ["E", "F", "I", "UP", "B", "SIM", "TCH"]
ignore = ["E501"]

[tool.ruff.format]
quote-style = "double"

[tool.pytest.ini_options]
testpaths = ["sdk/tests"]
asyncio_mode = "auto"
asyncio_default_fixture_loop_scope = "function"

[tool.mypy]
python_version = "3.9"
strict = true
warn_return_any = true
warn_unused_ignores = true

[tool.pyright]
pythonVersion = "3.9"
typeCheckingMode = "strict"

[dependency-groups]
dev = [
"mypy>=1.19.0",
"pytest>=8.4.2",
"pytest-asyncio>=1.2.0",
"pytest-cov>=7.0.0",
"python-dotenv>=1.2.1",
"ruff>=0.14.8",
]
67 changes: 67 additions & 0 deletions packages/py/sdk/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Context7 Python SDK

Python SDK for Context7 - Documentation retrieval for AI agents.

## Installation

```bash
pip install context7
```

Or with uv:

```bash
uv add context7
```

## Quick Start

```python
import asyncio
from context7-sdk import Context7

async def main():
async with Context7(api_key="ctx7sk_...") as client:
# Search for libraries
results = await client.search_library("react")
for lib in results.results:
print(f"{lib.id}: {lib.title}")

# Get documentation
docs = await client.get_docs("/facebook/react")
for snippet in docs.snippets:
print(f"{snippet.code_title}: {snippet.code_description}")

asyncio.run(main())
```

## API Reference

### `Context7(api_key=None, base_url=None)`

Initialize the Context7 client.

- `api_key`: API key for authentication. Falls back to `CONTEXT7_API_KEY` environment variable.
- `base_url`: Optional custom base URL for the API.

### `await client.search_library(query: str) -> SearchLibraryResponse`

Search for libraries by name or description.

### `await client.get_docs(library_id: str, **options) -> DocsResponse`

Get documentation for a library.

**Parameters:**

- `library_id`: Library identifier in format `/owner/repo` (e.g., `/facebook/react`)
- `version`: Optional library version (e.g., `"18.0.0"`)
- `page`: Page number for pagination
- `topic`: Filter docs by topic
- `limit`: Number of results per page
- `mode`: Type of documentation - `"code"` (default) or `"info"`
- `format`: Response format - `"json"` (default) or `"txt"`

## License

MIT
56 changes: 56 additions & 0 deletions packages/py/sdk/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
[project]
name = "context7"
version = "0.1.0"
description = "Python SDK for Context7 - Documentation retrieval for AI agents"
readme = "README.md"
requires-python = ">=3.9"
license = "MIT"
authors = [
{ name = "Upstash", email = "[email protected]" }
]
keywords = ["context7", "sdk", "documentation", "ai", "llm", "mcp", "upstash"]
classifiers = [
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Typing :: Typed",
]

dependencies = [
"httpx>=0.27.0",
"pydantic>=2.0.0",
]

[project.optional-dependencies]
dev = [
"pytest>=8.0.0",
"pytest-asyncio>=0.24.0",
"pytest-cov>=5.0.0",
"mypy>=1.11.0",
"ruff>=0.6.0",
]

[project.urls]
Homepage = "https://context7.com"
Documentation = "https://context7.com/docs"
Repository = "https://github.com/upstash/context7"
Issues = "https://github.com/upstash/context7/issues"

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.hatch.build.targets.wheel]
packages = ["src/context7"]

[tool.hatch.build.targets.sdist]
include = [
"/src",
"/tests",
]
Loading
Loading