Metadata-Version: 2.4
Name: forgein
Version: 0.1.0
Summary: Your project memory, available everywhere — Python SDK for forgein
Project-URL: Homepage, https://forgein.ai
Project-URL: Documentation, https://forgein.ai/docs
Project-URL: Repository, https://github.com/forgeinai/forgein
Project-URL: Bug Tracker, https://github.com/forgeinai/forgein/issues
Project-URL: Changelog, https://github.com/forgeinai/forgein/releases
Author-email: forgein <support@mails.forgein.ai>
License: MIT License
        
        Copyright (c) 2026 forgein
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: agents,ai,anthropic,claude,context,copilot,cursor,developer-tools,langchain,llm,memory,openai
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.9
Requires-Dist: httpx>=0.27.0
Requires-Dist: pydantic>=2.0.0
Provides-Extra: all
Requires-Dist: langchain-core>=0.1.0; extra == 'all'
Requires-Dist: typer>=0.12.0; extra == 'all'
Provides-Extra: cli
Requires-Dist: typer>=0.12.0; extra == 'cli'
Provides-Extra: dev
Requires-Dist: hatch; extra == 'dev'
Requires-Dist: mypy>=1.10; extra == 'dev'
Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
Requires-Dist: pytest>=8.0; extra == 'dev'
Requires-Dist: respx>=0.21; extra == 'dev'
Requires-Dist: ruff>=0.4; extra == 'dev'
Provides-Extra: langchain
Requires-Dist: langchain-core>=0.1.0; extra == 'langchain'
Description-Content-Type: text/markdown

<p align="center">
  <img src="https://forgein.ai/icon.png" width="80" alt="forgein logo" />
</p>

<h1 align="center">forgein</h1>

<p align="center">
  <b>Your project memory, available everywhere.</b><br/>
  Write your context once in Claude Code. Use it in any Python agent, LLM call, or AI pipeline.
</p>

<p align="center">
  <a href="https://pypi.org/project/forgein/"><img src="https://img.shields.io/pypi/v/forgein?color=f97316&label=PyPI" alt="PyPI version"></a>
  <a href="https://pypi.org/project/forgein/"><img src="https://img.shields.io/pypi/pyversions/forgein" alt="Python versions"></a>
  <a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="License: MIT"></a>
  <a href="https://forgein.ai"><img src="https://img.shields.io/badge/docs-forgein.ai-f97316" alt="Docs"></a>
</p>

---

## The problem

Your Claude Code memory lives in `CLAUDE.md`. Your Cursor rules in `.cursorrules`. Your Copilot instructions in `.github/copilot-instructions.md`. Every AI tool has its own silo — and none of them talk to each other.

When you write a prompt, spin up an agent, or call an API, you start from scratch — re-explaining your stack, your conventions, your current sprint — every single time.

## The fix

```bash
pip install forgein
```

```python
from forgein import ForgeinClient

client = ForgeinClient()  # reads FORGEIN_API_TOKEN
context = client.adapters.get("copilot", project="my-saas-app")
# → "# Project Context\n**Stack:** Next.js 15, TypeScript, PostgreSQL..."
```

One call. One source of truth. Works with Claude, OpenAI, Gemini, LangChain, and anything else that takes a string.

---

## Install

```bash
# Core SDK (sync + async)
pip install forgein

# With LangChain tool support
pip install "forgein[langchain]"

# With CLI
pip install "forgein[cli]"

# Everything
pip install "forgein[all]"
```

---

## Quick start

### 1. Get a token

```bash
# In Claude Code
/forgein auth
```

Or grab one at **[app.forgein.ai/tokens](https://app.forgein.ai/tokens)**.

### 2. Set the environment variable

```bash
export FORGEIN_API_TOKEN="fg_..."
```

### 3. Fetch context

```python
from forgein import ForgeinClient

with ForgeinClient() as client:
    # Get context for any AI tool
    copilot    = client.adapters.get("copilot",     project="my-saas-app")
    cursor     = client.adapters.get("cursor",      project="my-saas-app")
    claude_md  = client.adapters.get("claude-code", project="my-saas-app")

    # Or sync all context files to disk in one call
    result = client.adapters.sync("my-saas-app", path=".")
    # Writes: .github/copilot-instructions.md, .cursorrules,
    #         .windsurfrules, CLAUDE.md, .gemini/context.md
    print(f"{len(result.written)} files written")
```

---

## Integrations

### Anthropic / Claude

```python
import anthropic
from forgein import ForgeinClient

context = ForgeinClient().adapters.get("claude-code", project="my-saas-app")

client = anthropic.Anthropic()
message = client.messages.create(
    model="claude-opus-4-8",
    system=context,
    messages=[{"role": "user", "content": "Refactor the auth middleware"}],
    max_tokens=8192,
)
print(message.content[0].text)
```

Or use the integration helper:

```python
from forgein.integrations.anthropic import get_system_prompt

system = get_system_prompt("my-saas-app")  # defaults to claude-code adapter
```

### OpenAI

```python
from openai import OpenAI
from forgein.integrations.openai import get_system_message

client = OpenAI()
response = client.chat.completions.create(
    model="gpt-4o",
    messages=[
        get_system_message("my-saas-app"),  # → {"role": "system", "content": "..."}
        {"role": "user", "content": "How should I structure the Stripe webhook?"},
    ],
)
```

### LangChain

```python
from langchain_anthropic import ChatAnthropic
from langchain.agents import AgentExecutor, create_tool_calling_agent
from langchain_core.prompts import ChatPromptTemplate
from forgein.integrations.langchain import ForgeinContextTool

tools = [ForgeinContextTool(project="my-saas-app")]

llm = ChatAnthropic(model="claude-opus-4-8")
prompt = ChatPromptTemplate.from_messages([
    ("system", "You are a helpful coding assistant."),
    ("human", "{input}"),
    ("placeholder", "{agent_scratchpad}"),
])

agent = create_tool_calling_agent(llm, tools, prompt)
executor = AgentExecutor(agent=agent, tools=tools)
result = executor.invoke({"input": "What are the Drizzle ORM conventions in this project?"})
```

### Async

```python
import asyncio
from forgein import AsyncForgeinClient

async def main():
    async with AsyncForgeinClient() as client:
        # Fetch three adapters concurrently
        copilot, cursor, claude = await asyncio.gather(
            client.adapters.get("copilot",     project="my-saas-app"),
            client.adapters.get("cursor",      project="my-saas-app"),
            client.adapters.get("claude-code", project="my-saas-app"),
        )

asyncio.run(main())
```

---

## API reference

### `ForgeinClient(token=None, *, base_url=None, timeout=30.0, max_retries=3)`

| Parameter | Type | Description |
|-----------|------|-------------|
| `token` | `str \| None` | `fg_` API token. Falls back to `FORGEIN_API_TOKEN`. |
| `base_url` | `str \| None` | Override API URL. Falls back to `FORGEIN_BASE_URL`. |
| `timeout` | `float` | Request timeout in seconds. Default: 30. |
| `max_retries` | `int` | Retry attempts on 429 / 5xx. Default: 3. |

Supports context manager (`with ForgeinClient() as client:`).

`AsyncForgeinClient` has an identical signature and supports `async with`.

---

### `client.adapters`

| Method | Returns | Description |
|--------|---------|-------------|
| `.get(adapter, *, project)` | `str` | Fetch context string for one adapter |
| `.sync(project, *, path=".", adapters=None)` | `SyncResult` | Write context files to disk |
| `.usage()` | `AdapterUsage` | Per-adapter usage stats + 14-day sparkline |

**Available adapters:** `"copilot"` · `"claude-code"` · `"cursor"` · `"windsurf"` · `"gemini"` · `"chatgpt"`

**Files written by `.sync()`:**

| Adapter | File |
|---------|------|
| `copilot` | `.github/copilot-instructions.md` |
| `cursor` | `.cursorrules` |
| `windsurf` | `.windsurfrules` |
| `claude-code` | `CLAUDE.md` |
| `gemini` | `.gemini/context.md` |
| `chatgpt` | `.chatgpt/context.json` |

---

### `client.memory`

| Method | Returns | Description |
|--------|---------|-------------|
| `.list(project)` | `list[MemoryFileMeta]` | List files (no content) |
| `.get(project, path)` | `MemoryFile` | Read a single file |
| `.put(project, path, content)` | `MemoryFileMeta` | Create or update a file |
| `.delete(project, path)` | `None` | Delete a file |
| `.projects()` | `list[MemoryProject]` | All projects with file counts |
| `.search(query)` | `list[SearchResult]` | Full-text search |
| `.stats()` | `MemoryStats` | Aggregate counts and byte sizes |
| `.health()` | `MemoryHealth` | Stale-context detection |
| `.history(project, path)` | `list[MemoryHistoryEntry]` | Version history (max 50) |

---

### `client.tokens`

| Method | Returns | Description |
|--------|---------|-------------|
| `.list()` | `list[Token]` | All active tokens |
| `.create(name)` | `TokenCreated` | Create a token (raw value returned once) |
| `.revoke(token_id)` | `None` | Revoke by ID |

---

### `client.auth`

| Method | Returns | Description |
|--------|---------|-------------|
| `.me()` | `User` | Current user |
| `.change_password(current, new)` | `None` | Change password |
| `.export_data()` | `bytes` | Full JSON export |
| `.delete_account()` | `None` | Permanently delete account |

---

### `client.webhooks`

| Method | Returns | Description |
|--------|---------|-------------|
| `.list()` | `list[Webhook]` | All webhooks |
| `.create(url, events)` | `Webhook` | Create endpoint |
| `.delete(id)` | `None` | Delete |
| `.update(id, *, url, is_active)` | `Webhook` | Update |
| `.deliveries(id)` | `list[WebhookDelivery]` | Last 20 deliveries |
| `.ping(id)` | `WebhookDelivery` | Send test delivery |

---

### Additional resources

`client.contexts` · `client.shares` · `client.referrals` · `client.skills` · `client.waitlist`

All follow the same sync/async pattern. Full reference at [forgein.ai/docs/python](https://forgein.ai/docs/python).

---

## Error handling

```python
from forgein import ForgeinClient
from forgein.exceptions import (
    AuthenticationError,
    PermissionDeniedError,
    NotFoundError,
    RateLimitError,
    ServerError,
    NetworkError,
)

client = ForgeinClient()

try:
    context = client.adapters.get("copilot", project="my-saas-app")
except AuthenticationError:
    # Token missing, invalid, or revoked
    print("Run: forgein auth")
except PermissionDeniedError:
    # Pro-only feature
    print("Upgrade at app.forgein.ai/billing")
except RateLimitError as e:
    import time
    time.sleep(e.retry_after or 60)
except NotFoundError:
    print("Project not found — check the name")
except (ServerError, NetworkError) as e:
    print(f"Transient error: {e}")
```

All exceptions inherit from `forgein.exceptions.ForgeinError` and expose `.status_code` and `.response`.

---

## CLI

```bash
# Verify auth
forgein auth

# Print context to stdout
forgein context get my-saas-app --adapter copilot

# Sync all context files to current directory
forgein context sync my-saas-app

# List memory files
forgein memory list my-saas-app

# Read a file
forgein memory get my-saas-app CLAUDE.md

# Check API health
forgein health
```

---

## Environment variables

| Variable | Description |
|----------|-------------|
| `FORGEIN_API_TOKEN` | API token (`fg_...`) |
| `FORGEIN_BASE_URL` | Override API base URL (default: `https://api.forgein.ai`) |

---

## Requirements

- Python ≥ 3.9
- `httpx >= 0.27`
- `pydantic >= 2.0`

---

## License

MIT — see [LICENSE](LICENSE).

---

<p align="center">
  Made by <a href="https://forgein.ai">forgein</a> ·
  <a href="https://app.forgein.ai/tokens">Get a token</a> ·
  <a href="https://github.com/forgeinai/forgein/issues">Report an issue</a>
</p>
