Skip to main content

Your project memory, available everywhere — Python SDK for forgein

Project description

forgein logo

forgein

Your project memory, available everywhere.
Write your context once in Claude Code. Use it in any Python agent, LLM call, or AI pipeline.

PyPI version Python versions License: MIT Docs


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

pip install forgein
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

# 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

# In Claude Code
/forgein auth

Or grab one at app.forgein.ai/tokens.

2. Set the environment variable

export FORGEIN_API_TOKEN="fg_..."

3. Fetch context

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

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:

from forgein.integrations.anthropic import get_system_prompt

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

OpenAI

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

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

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.


Error handling

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

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


Made by forgein · Get a token · Report an issue

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

forgein-0.1.0.tar.gz (20.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

forgein-0.1.0-py3-none-any.whl (26.8 kB view details)

Uploaded Python 3

File details

Details for the file forgein-0.1.0.tar.gz.

File metadata

  • Download URL: forgein-0.1.0.tar.gz
  • Upload date:
  • Size: 20.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.13

File hashes

Hashes for forgein-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9564b78478164f305b780cc10417f9e4d1cc89b13b96384360ad5d1f1fd446ba
MD5 d5d640b75048e06229058ae0419ba773
BLAKE2b-256 76ff2b3717d969465d21c7dc9bc69546cfa3941a676bfdec34f31b7880475a22

See more details on using hashes here.

File details

Details for the file forgein-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: forgein-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 26.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.13

File hashes

Hashes for forgein-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bafeeb2f8c763c99039498ce3a71c9d63eaabc28808a5306c4a77874436bbf9d
MD5 c3d37c792c2bdab3cea60a1a17b1546e
BLAKE2b-256 2e0f5201c25e4ab79b133bf4057a40883e2b0b498f27579354f52782234f122e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page