Metadata-Version: 2.4
Name: mnemexa
Version: 0.1.0
Summary: Official Python SDK for Mnemexa — the Intelligent Memory OS for AI.
Project-URL: Homepage, https://mnemexa.com
Project-URL: Documentation, https://docs.mnemexa.com/python
Project-URL: Repository, https://github.com/mnemexa/python
Project-URL: Issues, https://github.com/mnemexa/python/issues
Project-URL: Changelog, https://github.com/mnemexa/python/blob/main/CHANGELOG.md
Author-email: Mnemexa <bizxengine@gmail.com>
License: MIT License
        
        Copyright (c) 2026 Mnemexa
        
        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,llm,memory,mnemexa,sdk
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
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 :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.9
Requires-Dist: httpx<1.0,>=0.27
Requires-Dist: pydantic<3.0,>=2.0
Provides-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.6; extra == 'dev'
Description-Content-Type: text/markdown

# Mnemexa — Python SDK

[![PyPI](https://img.shields.io/pypi/v/mnemexa.svg)](https://pypi.org/project/mnemexa/)
[![Python](https://img.shields.io/pypi/pyversions/mnemexa.svg)](https://pypi.org/project/mnemexa/)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)

Official Python SDK for [Mnemexa](https://mnemexa.com) — the **Intelligent Memory OS for AI**.

```bash
pip install mnemexa
```

## Quick start

```python
import mnemexa

client = mnemexa.Client()  # reads MNEMEXA_API_KEY from the environment

# Store a memory
result = client.memory.store(text="The customer's name is Maya.")
print(result.memory_id)

# Retrieve relevant memories
recall = client.memory.retrieve(query="who is the customer?", top_k=3)
for memory in recall.memories:
    print(memory.score, memory.text)

# Check workspace memory health
health = client.optimize.health()
print(f"Quality: {health.quality_score}/100, total: {health.signals.total_memories}")
```

## Async

The same surface is mirrored under `mnemexa.AsyncClient`:

```python
import asyncio
import mnemexa

async def main() -> None:
    async with mnemexa.AsyncClient() as client:
        result = await client.memory.store(text="The customer's name is Maya.")
        print(result.memory_id)

asyncio.run(main())
```

## Configuration

All client kwargs are optional. Precedence is **explicit kwarg > environment variable > default**.

| Setting | Constructor arg | Env var | Default |
|---|---|---|---|
| API key | `api_key=` | `MNEMEXA_API_KEY` (falls back to `BIZX_API_KEY`) | raises `AuthenticationError` |
| Base URL | `base_url=` | `MNEMEXA_BASE_URL` (falls back to `BIZX_BASE_URL`) | `https://api.mnemexa.com` |
| Timeout | `timeout=` | — | `30.0` seconds |
| Max retries | `max_retries=` | — | `2` |

```python
client = mnemexa.Client(
    api_key="mnx_...",
    base_url="https://api.mnemexa.com",
    timeout=15.0,
    max_retries=3,
)
```

## Endpoints

The SDK currently wraps four endpoints — full API documentation lives at [docs.mnemexa.com](https://docs.mnemexa.com).

| Resource | Method | Returns |
|---|---|---|
| `client.memory.store(text, meta)` | `POST /v1/memory/store` | `MemoryStoreResponse` |
| `client.memory.retrieve(query, top_k, min_score)` | `POST /v1/memory/retrieve` | `MemoryRetrieveResponse` |
| `client.events.ingest(event_type, payload)` | `POST /v1/events/ingest` | `EventIngestResponse` |
| `client.optimize.health()` | `GET /v1/optimize/health` | `OptimizeHealthResponse` |

All response objects are Pydantic models with `extra="allow"` — future server-side fields surface automatically without breaking your code.

## Error handling

Every error raised by the SDK inherits from `mnemexa.MnemexaError`. The hierarchy maps HTTP status codes to typed exceptions you can catch precisely:

```python
import mnemexa

try:
    client.memory.store(text="...")
except mnemexa.AuthenticationError:    # 401 — invalid API key
    ...
except mnemexa.PermissionError:        # 403 — suspended workspace
    ...
except mnemexa.ValidationError:        # 422 — bad request body
    ...
except mnemexa.RateLimitError as e:    # 429 — back off and retry
    print(f"Retry after {e.retry_after}s")
except mnemexa.ServiceUnavailableError:  # 5xx — backend transient
    ...
except mnemexa.MnemexaError as e:      # catch-all
    print(e.request_id)  # always populated when available
```

Every error carries `status_code`, `request_id`, and the parsed response `body` for easy support escalation.

### Retry policy

The SDK auto-retries with exponential backoff (capped at 8 seconds) on:

- Network errors and timeouts
- HTTP `502`, `503`, `504`

The SDK **never** auto-retries `401`, `403`, `404`, `422`, or `429`. For `429`, inspect `RateLimitError.retry_after` and back off on your own schedule.

## Logging

The SDK logs to a logger named `mnemexa`. By default no handler is attached — the host application's logging configuration is respected. Auth headers are always redacted from log lines.

```python
import logging
logging.getLogger("mnemexa").setLevel(logging.DEBUG)
```

## Links

- Homepage: [mnemexa.com](https://mnemexa.com)
- Documentation: [docs.mnemexa.com](https://docs.mnemexa.com)
- Source: [github.com/mnemexa/python](https://github.com/mnemexa/python)
- Issues: [github.com/mnemexa/python/issues](https://github.com/mnemexa/python/issues)
- Changelog: [CHANGELOG.md](CHANGELOG.md)

## License

MIT
