Skip to main content

Neurophic Python SDK

PyPI Python License

Official Python client for the Neurophic memory API.

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.

Installation

pip install neurophic

Requires Python 3.10+.

Usage

from neurophic import Neurophic

client = Neurophic(api_key="nph_xxx")  # or set NEUROPHIC_API_KEY

# Store what the user said. The write is queued and processed in the background.
client.ingest("user-123", "Loves hiking and photography")

# Before a model call, get a short block of relevant memories for the system prompt.
# An empty string when nothing is relevant.
context = client.context("user-123", "planning a weekend away")

Storing memories

# The receipt id becomes the memory id once the write is processed
receipt = client.ingest("user-123", "Loves hiking and photography")
print(receipt.id, receipt.status)  # 5f1d2c3e-... queued

# Backfill history: say when it was said, oldest first
client.ingest("user-123", "Moved to Bath last month", occurred_at="2026-03-14T10:30:00Z")

# Store what your agent said, so it can pick up where it left off
client.ingest("user-123", "Suggested the Cotswold Way for a first long hike", role="assistant")

Searching memory

# As Markdown, ready for a prompt
markdown = client.retrieve("user-123", "hobbies")

# Or as typed objects: memories, observations, patterns and the original turns, reranked before the cut
results = client.retrieve(
    "user-123",
    "what instruments do I play",
    format="json",
    roles=["user", "assistant"],
    sources=True,
    rerank="fast",
)

for memory in results.memories:
    print(memory.content)
    print(memory.role)         # user or assistant
    print(memory.occurred_at)  # datetime
    print(memory.relevance)    # None when rerank was used: the order is the ranking
    print(memory.source_id)    # id of the turn in results.sources

print(results.observations)  # recent writes not yet promoted to memories
print(results.patterns)      # summaries written from several memories, at most two
print(results.sources)       # the original turns, each once

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.

Every result is a pydantic model: results.model_dump() gives a dict and results.model_dump_json() JSON.

Async

AsyncNeurophic has the same calls, awaited.

from neurophic import AsyncNeurophic

async with AsyncNeurophic() as client:
    context = await client.context("user-123", "planning a weekend away")

Managing memories

memories = client.memory.list("user-123", page=1, per_page=20)
print(memories.total)

memory = client.memory.get(memories.memories[0].id, identifier="user-123")
print(memory.content)

# Remove the memory and every version it superseded
client.memory.delete(memory.id, identifier="user-123")

# Or delete only this version and restore the one it superseded
client.memory.delete(memory.id, identifier="user-123", restore_previous=True)

Configuration

client = Neurophic(
    api_key="nph_xxx",                    # Or set NEUROPHIC_API_KEY
    base_url="https://api.neurophic.ai",  # Or set NEUROPHIC_BASE_URL; default shown
    timeout=30,                           # Optional: seconds for each step of a request, an httpx.Timeout, or None
)

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.

Use the client as a context manager, or call close() (aclose() on the async client), to release its connections.

The installed version is neurophic.__version__.

Error handling

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:

Status Class
400 BadRequestError, with details on a validation error
401 AuthenticationError
402 InsufficientCreditError, with balance and required
403 PermissionDeniedError
404 NotFoundError
409 MemoryLimitError
429 RateLimitError
5xx InternalServerError, and ServiceUnavailableError for 503

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.

from neurophic import BadRequestError, InsufficientCreditError, NeurophicError

try:
    client.ingest("user-123", "Prefers window seats")
except BadRequestError as error:
    for detail in error.details:
        print(f"{detail.field}: {detail.message}")
except InsufficientCreditError as error:
    print(f"Balance {error.balance}, required {error.required}. Top up the project.")
except NeurophicError as error:
    # status_code is the HTTP status, 0 for timeouts and connection failures;
    # code is the API error code, for example "PROJECT_SUSPENDED": branch on it, not on message
    print(error.status_code, error.code, error.message)
    print(error.body)  # the decoded error body, for anything not modelled above

Documentation

Full reference at neurophic.ai/docs/sdk/python.

Versioning

The package follows semantic versioning. Until 1.0, a minor version can change the API; every change is listed in the changelog.

Development

From this package's folder in the neurophic-sdk-python repository:

uv sync
uv run ruff check && uv run ruff format --check
uv run mypy
uv run pytest

License

MIT

Metadata

Release files for neurophic 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for neurophic 0.1.0
File Size Uploaded Provenance Actions
neurophic-0.1.0.tar.gz 23.8 kB With provenance Details for neurophic-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for neurophic 0.1.0
File Interpreter ABI Platform Actions
neurophic-0.1.0-py3-none-any.whl Python 3 none any Details for neurophic-0.1.0-py3-none-any.whl

Total release size: 41.2 kB

Release files / neurophic-0.1.0.tar.gz

Download URL neurophic-0.1.0.tar.gz
Size 23.8 kB
Tags Source
SHA-256 checksum
How to use checksums
0204112290c4d352826238d52f9596a18af9076f8d3932e5e4c5dc2ec7967b9d
BLAKE2b-256 checksum
How to use checksums
3bbc92bde7cb9feb4e16a1e07ad0d84ca3ab08337ba633a7855f2ca3a4381f7c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 4, 2026.

Transparency log

Release files / neurophic-0.1.0-py3-none-any.whl

Download URL neurophic-0.1.0-py3-none-any.whl
Size 17.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fdd49780ea2cb6f8d80f6b2a7deca42ccc32e07059cc68cac36eff9a4f33c90d
BLAKE2b-256 checksum
How to use checksums
59ce697442649d9c9ba661e539ac3bf422c8d886d50827b5e47f827b9993ce6f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 4, 2026.

Transparency log

Security for neurophic 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for neurophic-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 4, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page