neurophic 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- neurophic-0.1.0/.gitignore +10 -0
- neurophic-0.1.0/CHANGELOG.md +14 -0
- neurophic-0.1.0/LICENSE +21 -0
- neurophic-0.1.0/PKG-INFO +207 -0
- neurophic-0.1.0/README.md +178 -0
- neurophic-0.1.0/pyproject.toml +67 -0
- neurophic-0.1.0/src/neurophic/__init__.py +79 -0
- neurophic-0.1.0/src/neurophic/_api.py +290 -0
- neurophic-0.1.0/src/neurophic/_client.py +605 -0
- neurophic-0.1.0/src/neurophic/_version.py +1 -0
- neurophic-0.1.0/src/neurophic/errors.py +276 -0
- neurophic-0.1.0/src/neurophic/py.typed +0 -0
- neurophic-0.1.0/src/neurophic/types.py +151 -0
- neurophic-0.1.0/tests/__init__.py +0 -0
- neurophic-0.1.0/tests/conftest.py +34 -0
- neurophic-0.1.0/tests/helpers.py +103 -0
- neurophic-0.1.0/tests/test_api.py +62 -0
- neurophic-0.1.0/tests/test_async.py +135 -0
- neurophic-0.1.0/tests/test_calls.py +244 -0
- neurophic-0.1.0/tests/test_client.py +122 -0
- neurophic-0.1.0/tests/test_errors.py +364 -0
- neurophic-0.1.0/tests/test_memory.py +107 -0
- neurophic-0.1.0/tests/test_mirror.py +36 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0 - 2026-12-04
|
|
4
|
+
|
|
5
|
+
The first release: a typed client for every endpoint of the Neurophic memory API.
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- `Neurophic` and `AsyncNeurophic` clients with `ingest()`, `context()` and `retrieve()`; the API key falls back to `NEUROPHIC_API_KEY`.
|
|
10
|
+
- `retrieve()` returns Markdown ready for a prompt, or typed results with `format="json"`.
|
|
11
|
+
- `client.memory.list()`, `get()` and `delete()`, with `restore_previous` on delete.
|
|
12
|
+
- `MemoryRole` and `RerankMode` enums, with plain strings accepted too; dates as ISO 8601 strings, `date` or `datetime`.
|
|
13
|
+
- `NeurophicError` with the API's `status_code` and `code`, raised as a subclass per status such as `AuthenticationError` and `NotFoundError`; `NeurophicTimeoutError` and `NeurophicConnectionError` for transport failures.
|
|
14
|
+
- Python 3.10 or later, on httpx and pydantic.
|
neurophic-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Neurophic
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
neurophic-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: neurophic
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python client for the Neurophic memory API
|
|
5
|
+
Project-URL: Homepage, https://neurophic.ai
|
|
6
|
+
Project-URL: Documentation, https://neurophic.ai/docs/sdk/python
|
|
7
|
+
Project-URL: Repository, https://github.com/neurophic/neurophic-sdk-python
|
|
8
|
+
Project-URL: Changelog, https://github.com/neurophic/neurophic-sdk-python/blob/main/packages/neurophic/CHANGELOG.md
|
|
9
|
+
Project-URL: Issues, https://github.com/neurophic/neurophic-sdk-python/issues
|
|
10
|
+
Author-email: Neurophic <info@neurophic.ai>
|
|
11
|
+
License-Expression: MIT
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Keywords: agents,ai,memory,neurophic,sdk
|
|
14
|
+
Classifier: Development Status :: 4 - Beta
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
23
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
24
|
+
Classifier: Typing :: Typed
|
|
25
|
+
Requires-Python: >=3.10
|
|
26
|
+
Requires-Dist: httpx<1,>=0.27
|
|
27
|
+
Requires-Dist: pydantic<3,>=2.11
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
|
|
30
|
+
# Neurophic Python SDK
|
|
31
|
+
|
|
32
|
+
[](https://pypi.org/project/neurophic/)
|
|
33
|
+
[](https://pypi.org/project/neurophic/)
|
|
34
|
+
[](https://github.com/neurophic/neurophic-sdk-python/blob/main/packages/neurophic/LICENSE)
|
|
35
|
+
|
|
36
|
+
Official Python client for the [Neurophic](https://neurophic.ai) memory API.
|
|
37
|
+
|
|
38
|
+
Neurophic is an adaptive memory layer for AI agents. Each of your users gets their own memory that learns and changes with them: send what they say, and get back what matters when your agent needs it.
|
|
39
|
+
|
|
40
|
+
## Installation
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
pip install neurophic
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Requires Python 3.10+.
|
|
47
|
+
|
|
48
|
+
## Usage
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
from neurophic import Neurophic
|
|
52
|
+
|
|
53
|
+
client = Neurophic(api_key="nph_xxx") # or set NEUROPHIC_API_KEY
|
|
54
|
+
|
|
55
|
+
# Store what the user said. The write is queued and processed in the background.
|
|
56
|
+
client.ingest("user-123", "Loves hiking and photography")
|
|
57
|
+
|
|
58
|
+
# Before a model call, get a short block of relevant memories for the system prompt.
|
|
59
|
+
# An empty string when nothing is relevant.
|
|
60
|
+
context = client.context("user-123", "planning a weekend away")
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Storing memories
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
# The receipt id becomes the memory id once the write is processed
|
|
67
|
+
receipt = client.ingest("user-123", "Loves hiking and photography")
|
|
68
|
+
print(receipt.id, receipt.status) # 5f1d2c3e-... queued
|
|
69
|
+
|
|
70
|
+
# Backfill history: say when it was said, oldest first
|
|
71
|
+
client.ingest("user-123", "Moved to Bath last month", occurred_at="2026-03-14T10:30:00Z")
|
|
72
|
+
|
|
73
|
+
# Store what your agent said, so it can pick up where it left off
|
|
74
|
+
client.ingest("user-123", "Suggested the Cotswold Way for a first long hike", role="assistant")
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Searching memory
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
# As Markdown, ready for a prompt
|
|
81
|
+
markdown = client.retrieve("user-123", "hobbies")
|
|
82
|
+
|
|
83
|
+
# Or as typed objects: memories, observations, patterns and the original turns, reranked before the cut
|
|
84
|
+
results = client.retrieve(
|
|
85
|
+
"user-123",
|
|
86
|
+
"what instruments do I play",
|
|
87
|
+
format="json",
|
|
88
|
+
roles=["user", "assistant"],
|
|
89
|
+
sources=True,
|
|
90
|
+
rerank="fast",
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
for memory in results.memories:
|
|
94
|
+
print(memory.content)
|
|
95
|
+
print(memory.role) # user or assistant
|
|
96
|
+
print(memory.occurred_at) # datetime
|
|
97
|
+
print(memory.relevance) # None when rerank was used: the order is the ranking
|
|
98
|
+
print(memory.source_id) # id of the turn in results.sources
|
|
99
|
+
|
|
100
|
+
print(results.observations) # recent writes not yet promoted to memories
|
|
101
|
+
print(results.patterns) # summaries written from several memories, at most two
|
|
102
|
+
print(results.sources) # the original turns, each once
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Every date argument (`occurred_at`, `since`, `until`, `reference_date`) takes an ISO 8601 string, a `date` or a `datetime`. A naive `datetime` is sent as UTC, and times are sent to the millisecond. `MemoryRole` and `RerankMode` enums are available wherever a plain string is accepted.
|
|
106
|
+
|
|
107
|
+
Every result is a [pydantic](https://docs.pydantic.dev) model: `results.model_dump()` gives a dict and `results.model_dump_json()` JSON.
|
|
108
|
+
|
|
109
|
+
### Async
|
|
110
|
+
|
|
111
|
+
`AsyncNeurophic` has the same calls, awaited.
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
from neurophic import AsyncNeurophic
|
|
115
|
+
|
|
116
|
+
async with AsyncNeurophic() as client:
|
|
117
|
+
context = await client.context("user-123", "planning a weekend away")
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Managing memories
|
|
121
|
+
|
|
122
|
+
```python
|
|
123
|
+
memories = client.memory.list("user-123", page=1, per_page=20)
|
|
124
|
+
print(memories.total)
|
|
125
|
+
|
|
126
|
+
memory = client.memory.get(memories.memories[0].id, identifier="user-123")
|
|
127
|
+
print(memory.content)
|
|
128
|
+
|
|
129
|
+
# Remove the memory and every version it superseded
|
|
130
|
+
client.memory.delete(memory.id, identifier="user-123")
|
|
131
|
+
|
|
132
|
+
# Or delete only this version and restore the one it superseded
|
|
133
|
+
client.memory.delete(memory.id, identifier="user-123", restore_previous=True)
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## Configuration
|
|
137
|
+
|
|
138
|
+
```python
|
|
139
|
+
client = Neurophic(
|
|
140
|
+
api_key="nph_xxx", # Or set NEUROPHIC_API_KEY
|
|
141
|
+
base_url="https://api.neurophic.ai", # Or set NEUROPHIC_BASE_URL; default shown
|
|
142
|
+
timeout=30, # Optional: seconds for each step of a request, an httpx.Timeout, or None
|
|
143
|
+
)
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
Pass your own `httpx.Client` (or `httpx.AsyncClient`) as `http_client` to add a proxy or event hooks. It keeps its own timeout unless you set `timeout`. The client never retries; add your own backoff if you need it.
|
|
147
|
+
|
|
148
|
+
Use the client as a context manager, or call `close()` (`aclose()` on the async client), to release its connections.
|
|
149
|
+
|
|
150
|
+
The installed version is `neurophic.__version__`.
|
|
151
|
+
|
|
152
|
+
## Error handling
|
|
153
|
+
|
|
154
|
+
Every HTTP and transport failure raises `neurophic.NeurophicError`. A response outside the 2xx range raises the subclass for its status, so you can catch what you expect by name and let the rest through:
|
|
155
|
+
|
|
156
|
+
| Status | Class |
|
|
157
|
+
|---|---|
|
|
158
|
+
| 400 | `BadRequestError`, with `details` on a validation error |
|
|
159
|
+
| 401 | `AuthenticationError` |
|
|
160
|
+
| 402 | `InsufficientCreditError`, with `balance` and `required` |
|
|
161
|
+
| 403 | `PermissionDeniedError` |
|
|
162
|
+
| 404 | `NotFoundError` |
|
|
163
|
+
| 409 | `MemoryLimitError` |
|
|
164
|
+
| 429 | `RateLimitError` |
|
|
165
|
+
| 5xx | `InternalServerError`, and `ServiceUnavailableError` for 503 |
|
|
166
|
+
|
|
167
|
+
Timeouts raise `NeurophicTimeoutError` and network failures `NeurophicConnectionError`; both have `status_code` `0`. A success response the client cannot read, not JSON or not the expected shape, raises `InvalidResponseError`, which usually means the API has changed and the client needs updating.
|
|
168
|
+
|
|
169
|
+
```python
|
|
170
|
+
from neurophic import BadRequestError, InsufficientCreditError, NeurophicError
|
|
171
|
+
|
|
172
|
+
try:
|
|
173
|
+
client.ingest("user-123", "Prefers window seats")
|
|
174
|
+
except BadRequestError as error:
|
|
175
|
+
for detail in error.details:
|
|
176
|
+
print(f"{detail.field}: {detail.message}")
|
|
177
|
+
except InsufficientCreditError as error:
|
|
178
|
+
print(f"Balance {error.balance}, required {error.required}. Top up the project.")
|
|
179
|
+
except NeurophicError as error:
|
|
180
|
+
# status_code is the HTTP status, 0 for timeouts and connection failures;
|
|
181
|
+
# code is the API error code, for example "PROJECT_SUSPENDED": branch on it, not on message
|
|
182
|
+
print(error.status_code, error.code, error.message)
|
|
183
|
+
print(error.body) # the decoded error body, for anything not modelled above
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
## Documentation
|
|
187
|
+
|
|
188
|
+
Full reference at [neurophic.ai/docs/sdk/python](https://neurophic.ai/docs/sdk/python).
|
|
189
|
+
|
|
190
|
+
## Versioning
|
|
191
|
+
|
|
192
|
+
The package follows semantic versioning. Until 1.0, a minor version can change the API; every change is listed in the [changelog](https://github.com/neurophic/neurophic-sdk-python/blob/main/packages/neurophic/CHANGELOG.md).
|
|
193
|
+
|
|
194
|
+
## Development
|
|
195
|
+
|
|
196
|
+
From this package's folder in the [neurophic-sdk-python](https://github.com/neurophic/neurophic-sdk-python) repository:
|
|
197
|
+
|
|
198
|
+
```bash
|
|
199
|
+
uv sync
|
|
200
|
+
uv run ruff check && uv run ruff format --check
|
|
201
|
+
uv run mypy
|
|
202
|
+
uv run pytest
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
## License
|
|
206
|
+
|
|
207
|
+
MIT
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
# Neurophic Python SDK
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/neurophic/)
|
|
4
|
+
[](https://pypi.org/project/neurophic/)
|
|
5
|
+
[](https://github.com/neurophic/neurophic-sdk-python/blob/main/packages/neurophic/LICENSE)
|
|
6
|
+
|
|
7
|
+
Official Python client for the [Neurophic](https://neurophic.ai) memory API.
|
|
8
|
+
|
|
9
|
+
Neurophic is an adaptive memory layer for AI agents. Each of your users gets their own memory that learns and changes with them: send what they say, and get back what matters when your agent needs it.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pip install neurophic
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Requires Python 3.10+.
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
from neurophic import Neurophic
|
|
23
|
+
|
|
24
|
+
client = Neurophic(api_key="nph_xxx") # or set NEUROPHIC_API_KEY
|
|
25
|
+
|
|
26
|
+
# Store what the user said. The write is queued and processed in the background.
|
|
27
|
+
client.ingest("user-123", "Loves hiking and photography")
|
|
28
|
+
|
|
29
|
+
# Before a model call, get a short block of relevant memories for the system prompt.
|
|
30
|
+
# An empty string when nothing is relevant.
|
|
31
|
+
context = client.context("user-123", "planning a weekend away")
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Storing memories
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
# The receipt id becomes the memory id once the write is processed
|
|
38
|
+
receipt = client.ingest("user-123", "Loves hiking and photography")
|
|
39
|
+
print(receipt.id, receipt.status) # 5f1d2c3e-... queued
|
|
40
|
+
|
|
41
|
+
# Backfill history: say when it was said, oldest first
|
|
42
|
+
client.ingest("user-123", "Moved to Bath last month", occurred_at="2026-03-14T10:30:00Z")
|
|
43
|
+
|
|
44
|
+
# Store what your agent said, so it can pick up where it left off
|
|
45
|
+
client.ingest("user-123", "Suggested the Cotswold Way for a first long hike", role="assistant")
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Searching memory
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
# As Markdown, ready for a prompt
|
|
52
|
+
markdown = client.retrieve("user-123", "hobbies")
|
|
53
|
+
|
|
54
|
+
# Or as typed objects: memories, observations, patterns and the original turns, reranked before the cut
|
|
55
|
+
results = client.retrieve(
|
|
56
|
+
"user-123",
|
|
57
|
+
"what instruments do I play",
|
|
58
|
+
format="json",
|
|
59
|
+
roles=["user", "assistant"],
|
|
60
|
+
sources=True,
|
|
61
|
+
rerank="fast",
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
for memory in results.memories:
|
|
65
|
+
print(memory.content)
|
|
66
|
+
print(memory.role) # user or assistant
|
|
67
|
+
print(memory.occurred_at) # datetime
|
|
68
|
+
print(memory.relevance) # None when rerank was used: the order is the ranking
|
|
69
|
+
print(memory.source_id) # id of the turn in results.sources
|
|
70
|
+
|
|
71
|
+
print(results.observations) # recent writes not yet promoted to memories
|
|
72
|
+
print(results.patterns) # summaries written from several memories, at most two
|
|
73
|
+
print(results.sources) # the original turns, each once
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Every date argument (`occurred_at`, `since`, `until`, `reference_date`) takes an ISO 8601 string, a `date` or a `datetime`. A naive `datetime` is sent as UTC, and times are sent to the millisecond. `MemoryRole` and `RerankMode` enums are available wherever a plain string is accepted.
|
|
77
|
+
|
|
78
|
+
Every result is a [pydantic](https://docs.pydantic.dev) model: `results.model_dump()` gives a dict and `results.model_dump_json()` JSON.
|
|
79
|
+
|
|
80
|
+
### Async
|
|
81
|
+
|
|
82
|
+
`AsyncNeurophic` has the same calls, awaited.
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
from neurophic import AsyncNeurophic
|
|
86
|
+
|
|
87
|
+
async with AsyncNeurophic() as client:
|
|
88
|
+
context = await client.context("user-123", "planning a weekend away")
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Managing memories
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
memories = client.memory.list("user-123", page=1, per_page=20)
|
|
95
|
+
print(memories.total)
|
|
96
|
+
|
|
97
|
+
memory = client.memory.get(memories.memories[0].id, identifier="user-123")
|
|
98
|
+
print(memory.content)
|
|
99
|
+
|
|
100
|
+
# Remove the memory and every version it superseded
|
|
101
|
+
client.memory.delete(memory.id, identifier="user-123")
|
|
102
|
+
|
|
103
|
+
# Or delete only this version and restore the one it superseded
|
|
104
|
+
client.memory.delete(memory.id, identifier="user-123", restore_previous=True)
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Configuration
|
|
108
|
+
|
|
109
|
+
```python
|
|
110
|
+
client = Neurophic(
|
|
111
|
+
api_key="nph_xxx", # Or set NEUROPHIC_API_KEY
|
|
112
|
+
base_url="https://api.neurophic.ai", # Or set NEUROPHIC_BASE_URL; default shown
|
|
113
|
+
timeout=30, # Optional: seconds for each step of a request, an httpx.Timeout, or None
|
|
114
|
+
)
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Pass your own `httpx.Client` (or `httpx.AsyncClient`) as `http_client` to add a proxy or event hooks. It keeps its own timeout unless you set `timeout`. The client never retries; add your own backoff if you need it.
|
|
118
|
+
|
|
119
|
+
Use the client as a context manager, or call `close()` (`aclose()` on the async client), to release its connections.
|
|
120
|
+
|
|
121
|
+
The installed version is `neurophic.__version__`.
|
|
122
|
+
|
|
123
|
+
## Error handling
|
|
124
|
+
|
|
125
|
+
Every HTTP and transport failure raises `neurophic.NeurophicError`. A response outside the 2xx range raises the subclass for its status, so you can catch what you expect by name and let the rest through:
|
|
126
|
+
|
|
127
|
+
| Status | Class |
|
|
128
|
+
|---|---|
|
|
129
|
+
| 400 | `BadRequestError`, with `details` on a validation error |
|
|
130
|
+
| 401 | `AuthenticationError` |
|
|
131
|
+
| 402 | `InsufficientCreditError`, with `balance` and `required` |
|
|
132
|
+
| 403 | `PermissionDeniedError` |
|
|
133
|
+
| 404 | `NotFoundError` |
|
|
134
|
+
| 409 | `MemoryLimitError` |
|
|
135
|
+
| 429 | `RateLimitError` |
|
|
136
|
+
| 5xx | `InternalServerError`, and `ServiceUnavailableError` for 503 |
|
|
137
|
+
|
|
138
|
+
Timeouts raise `NeurophicTimeoutError` and network failures `NeurophicConnectionError`; both have `status_code` `0`. A success response the client cannot read, not JSON or not the expected shape, raises `InvalidResponseError`, which usually means the API has changed and the client needs updating.
|
|
139
|
+
|
|
140
|
+
```python
|
|
141
|
+
from neurophic import BadRequestError, InsufficientCreditError, NeurophicError
|
|
142
|
+
|
|
143
|
+
try:
|
|
144
|
+
client.ingest("user-123", "Prefers window seats")
|
|
145
|
+
except BadRequestError as error:
|
|
146
|
+
for detail in error.details:
|
|
147
|
+
print(f"{detail.field}: {detail.message}")
|
|
148
|
+
except InsufficientCreditError as error:
|
|
149
|
+
print(f"Balance {error.balance}, required {error.required}. Top up the project.")
|
|
150
|
+
except NeurophicError as error:
|
|
151
|
+
# status_code is the HTTP status, 0 for timeouts and connection failures;
|
|
152
|
+
# code is the API error code, for example "PROJECT_SUSPENDED": branch on it, not on message
|
|
153
|
+
print(error.status_code, error.code, error.message)
|
|
154
|
+
print(error.body) # the decoded error body, for anything not modelled above
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## Documentation
|
|
158
|
+
|
|
159
|
+
Full reference at [neurophic.ai/docs/sdk/python](https://neurophic.ai/docs/sdk/python).
|
|
160
|
+
|
|
161
|
+
## Versioning
|
|
162
|
+
|
|
163
|
+
The package follows semantic versioning. Until 1.0, a minor version can change the API; every change is listed in the [changelog](https://github.com/neurophic/neurophic-sdk-python/blob/main/packages/neurophic/CHANGELOG.md).
|
|
164
|
+
|
|
165
|
+
## Development
|
|
166
|
+
|
|
167
|
+
From this package's folder in the [neurophic-sdk-python](https://github.com/neurophic/neurophic-sdk-python) repository:
|
|
168
|
+
|
|
169
|
+
```bash
|
|
170
|
+
uv sync
|
|
171
|
+
uv run ruff check && uv run ruff format --check
|
|
172
|
+
uv run mypy
|
|
173
|
+
uv run pytest
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
## License
|
|
177
|
+
|
|
178
|
+
MIT
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.27"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "neurophic"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = "Python client for the Neurophic memory API"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
license-files = ["LICENSE"]
|
|
12
|
+
requires-python = ">=3.10"
|
|
13
|
+
authors = [{ name = "Neurophic", email = "info@neurophic.ai" }]
|
|
14
|
+
keywords = ["neurophic", "memory", "ai", "agents", "sdk"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 4 - Beta",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"Operating System :: OS Independent",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Programming Language :: Python :: 3.10",
|
|
21
|
+
"Programming Language :: Python :: 3.11",
|
|
22
|
+
"Programming Language :: Python :: 3.12",
|
|
23
|
+
"Programming Language :: Python :: 3.13",
|
|
24
|
+
"Programming Language :: Python :: 3.14",
|
|
25
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
26
|
+
"Typing :: Typed",
|
|
27
|
+
]
|
|
28
|
+
dependencies = [
|
|
29
|
+
"httpx>=0.27,<1",
|
|
30
|
+
"pydantic>=2.11,<3",
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
[project.urls]
|
|
34
|
+
Homepage = "https://neurophic.ai"
|
|
35
|
+
Documentation = "https://neurophic.ai/docs/sdk/python"
|
|
36
|
+
Repository = "https://github.com/neurophic/neurophic-sdk-python"
|
|
37
|
+
Changelog = "https://github.com/neurophic/neurophic-sdk-python/blob/main/packages/neurophic/CHANGELOG.md"
|
|
38
|
+
Issues = "https://github.com/neurophic/neurophic-sdk-python/issues"
|
|
39
|
+
|
|
40
|
+
[dependency-groups]
|
|
41
|
+
dev = [
|
|
42
|
+
"mypy>=1.15",
|
|
43
|
+
"pytest>=8",
|
|
44
|
+
"pytest-asyncio>=0.24",
|
|
45
|
+
"respx>=0.22",
|
|
46
|
+
"ruff>=0.8",
|
|
47
|
+
]
|
|
48
|
+
|
|
49
|
+
[tool.hatch.version]
|
|
50
|
+
path = "src/neurophic/_version.py"
|
|
51
|
+
|
|
52
|
+
[tool.hatch.build.targets.sdist]
|
|
53
|
+
include = ["src/neurophic", "tests", "CHANGELOG.md", "LICENSE", "README.md", "pyproject.toml"]
|
|
54
|
+
|
|
55
|
+
[tool.hatch.build.targets.wheel]
|
|
56
|
+
packages = ["src/neurophic"]
|
|
57
|
+
|
|
58
|
+
[tool.mypy]
|
|
59
|
+
python_version = "3.10"
|
|
60
|
+
strict = true
|
|
61
|
+
files = ["src", "tests"]
|
|
62
|
+
|
|
63
|
+
[tool.pytest.ini_options]
|
|
64
|
+
testpaths = ["tests"]
|
|
65
|
+
asyncio_mode = "auto"
|
|
66
|
+
asyncio_default_fixture_loop_scope = "function"
|
|
67
|
+
filterwarnings = ["error"]
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"""Python client for the Neurophic memory API. See https://neurophic.ai/docs/sdk/python."""
|
|
2
|
+
|
|
3
|
+
from ._client import (
|
|
4
|
+
DEFAULT_BASE_URL,
|
|
5
|
+
DEFAULT_TIMEOUT,
|
|
6
|
+
NOT_GIVEN,
|
|
7
|
+
AsyncMemoryResource,
|
|
8
|
+
AsyncNeurophic,
|
|
9
|
+
MemoryResource,
|
|
10
|
+
Neurophic,
|
|
11
|
+
NotGiven,
|
|
12
|
+
)
|
|
13
|
+
from ._version import __version__
|
|
14
|
+
from .errors import (
|
|
15
|
+
AuthenticationError,
|
|
16
|
+
BadRequestError,
|
|
17
|
+
ErrorCode,
|
|
18
|
+
InsufficientCreditError,
|
|
19
|
+
InternalServerError,
|
|
20
|
+
InvalidResponseError,
|
|
21
|
+
MemoryLimitError,
|
|
22
|
+
NeurophicConnectionError,
|
|
23
|
+
NeurophicError,
|
|
24
|
+
NeurophicTimeoutError,
|
|
25
|
+
NotFoundError,
|
|
26
|
+
PermissionDeniedError,
|
|
27
|
+
RateLimitError,
|
|
28
|
+
ServiceUnavailableError,
|
|
29
|
+
ValidationDetail,
|
|
30
|
+
)
|
|
31
|
+
from .types import (
|
|
32
|
+
IngestResult,
|
|
33
|
+
MemoryList,
|
|
34
|
+
MemoryRole,
|
|
35
|
+
MemorySummary,
|
|
36
|
+
RerankMode,
|
|
37
|
+
RetrievedMemory,
|
|
38
|
+
RetrievedObservation,
|
|
39
|
+
RetrievedPattern,
|
|
40
|
+
RetrievedSource,
|
|
41
|
+
RetrieveResult,
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
__all__ = [
|
|
45
|
+
"DEFAULT_BASE_URL",
|
|
46
|
+
"DEFAULT_TIMEOUT",
|
|
47
|
+
"NOT_GIVEN",
|
|
48
|
+
"AsyncMemoryResource",
|
|
49
|
+
"AsyncNeurophic",
|
|
50
|
+
"AuthenticationError",
|
|
51
|
+
"BadRequestError",
|
|
52
|
+
"ErrorCode",
|
|
53
|
+
"IngestResult",
|
|
54
|
+
"InsufficientCreditError",
|
|
55
|
+
"InternalServerError",
|
|
56
|
+
"InvalidResponseError",
|
|
57
|
+
"MemoryLimitError",
|
|
58
|
+
"MemoryList",
|
|
59
|
+
"MemoryResource",
|
|
60
|
+
"MemoryRole",
|
|
61
|
+
"MemorySummary",
|
|
62
|
+
"Neurophic",
|
|
63
|
+
"NeurophicConnectionError",
|
|
64
|
+
"NeurophicError",
|
|
65
|
+
"NeurophicTimeoutError",
|
|
66
|
+
"NotFoundError",
|
|
67
|
+
"NotGiven",
|
|
68
|
+
"PermissionDeniedError",
|
|
69
|
+
"RateLimitError",
|
|
70
|
+
"RerankMode",
|
|
71
|
+
"RetrieveResult",
|
|
72
|
+
"RetrievedMemory",
|
|
73
|
+
"RetrievedObservation",
|
|
74
|
+
"RetrievedPattern",
|
|
75
|
+
"RetrievedSource",
|
|
76
|
+
"ServiceUnavailableError",
|
|
77
|
+
"ValidationDetail",
|
|
78
|
+
"__version__",
|
|
79
|
+
]
|