# GoodMem Python SDK

A Python SDK designed to be easy to use and easy to maintain. OpenAI-style API with auto-inference of model parameters, streaming retrieval, async support, and auto-pagination.

The SDK stays in sync with the server's OpenAPI spec — except for hand-written convenience methods (model registry auto-inference, flat post-processor kwargs, etc.) that wrap the generated layer.

## Installation

```bash
pip install goodmem
```

## Usage

```python
from goodmem import Goodmem

client = Goodmem(
    base_url="http://localhost:8080",
    api_key="gm_..."
)

embedder = client.embedders.create(
    display_name="OpenAI Embedder",
    model_identifier="text-embedding-3-large",
    api_key="sk-your-openai-key",
)

print(f"Created: {embedder.embedder_id}")
```

## Project structure

```
clients/python2/
├── goodmem/                        # Installable package
│   ├── client.py                   # Goodmem / AsyncGoodmem entry points
│   ├── errors.py                   # Typed exception hierarchy (APIError, NotFoundError, …)
│   ├── pagination.py               # Paginator / AsyncPaginator (auto next_token)
│   ├── streaming.py                # RetrieveMemoryStream (SSE → typed events)
│   ├── _base.py                    # CRUDNamespace / AsyncCRUDNamespace base classes
│   ├── _schema_bridge.py           # Generated constants (credential builders, enums)
│   ├── _registries.py              # Generated model-registry loader
│   ├── api/                        # Tier-3: hand-written convenience overrides
│   │   ├── embedders.py            #   5 override classes (embedders, llms, rerankers,
│   │   ├── llms.py                 #     spaces, memories) call apply_convenience_transforms
│   │   ├── rerankers.py            #     then super()
│   │   ├── spaces.py               #   5 thin pass-throughs (apikeys, users, ocr,
│   │   ├── memories.py             #     system, admin) — just `pass`
│   │   └── ...
│   ├── registries/                 # Declarative config (no code generation)
│   │   ├── convenience.py          #   Source of truth for transforms, param descriptions,
│   │   │                           #     defaults, maps_to/replaces semantics
│   │   ├── embedders.json          #   29 embedder models (provider, dims, modalities)
│   │   ├── llms.json               #   34 LLM models
│   │   └── rerankers.json          #   16 reranker models
│   └── _generated/                 # Auto-generated — do not edit
│       ├── models/                 #   Tier-1: pydantic v2 models (openapi-generator)
│       └── api/                    #   Tier-2: structural API bases (_sdk_gen/ output)
│           ├── embedders_base.py
│           ├── memories_base.py
│           └── ...
├── _sdk_gen/                       # Tier-2 code generator (reads OpenAPI spec → emits bases)
│   ├── emitters.py                 #   Method emitters (input×output shape composition)
│   ├── spec.py                     #   Route classification, streaming/merge configs
│   ├── bridge.py                   #   Generates _schema_bridge.py + _registries.py
│   ├── docstrings.py               #   Docstring builder from OpenAPI summaries/params
│   ├── metadata.py                 #   REST metadata extraction (paths, models, params)
│   └── validate.py                 #   9 structural validation checks
├── tests/                          # Unit + validation tests (run without server)
│   ├── test_convenience_registry.py
│   ├── test_validate.py            #   Wraps _sdk_gen/validate.py checks as pytest
│   ├── test_*.py
│   └── integration/                # Live server tests (auto-skip without env vars)
│       ├── conftest.py
│       ├── test_full_flow.py
│       └── ...
├── docs/                           # Internal dev docs
│   ├── sdk_gen.md                  #   Architecture + regeneration guide
│   ├── doc_gen.md                  #   Doc generation + docstring authoring
│   └── ...
├── examples/
│   └── basic_rag.py                # End-to-end RAG example
├── generate.sh                     # Full pipeline: compile server → Tier-1 → Tier-2 → tests
├── generate_docs.py                # SDK ref doc generator (griffe + convenience registry → MDX)
└── pyproject.toml
```

For architecture details, regeneration workflows, and testing, see [docs/sdk_gen.md](docs/sdk_gen.md).

## Documentation

* [SDK generation guide](docs/sdk_gen.md) — architecture, regeneration, testing, tier details
* [Doc generation guide](docs/doc_gen.md) — how ref docs are generated, docstring authoring
* [CI pipeline](ci/README.md) — GitHub Actions workflow, secrets, Fly.io test server setup
* [API reference](https://docs.goodmem.ai/docs/reference/sdk/python2) — published SDK docs

## TODO

1. Add CI/CD pipeline to publish to PyPI. Integrate into ../build_all.sh and build_client.sh.
2. Add CI/CD pipeline to trigger SDK regeneration when server's OpenAPI spec changes.
3. How do we integrate the CI/CD for python2/ SDK with the pan-language SDK build system? `build_all.sh` and `build_client.sh`.
4. Add `gemini-embedding-001` to embedder registry once backend adds `OPENAI_COMPATIBLE` to `ProviderType`.
5. Add Anthropic, Google, Cohere, and Mistral LLMs to registry once backend adds matching `LLMProviderType` values.
