> ## Documentation Index
> Fetch the complete documentation index at: https://agno-v2-service-account.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Standalone Memory Manager CRUD

> Add, get, delete, and replace user memories manually.

```python standalone_memory.py theme={null}
"""
Standalone Memory Manager CRUD
==============================

This example shows how to add, get, delete, and replace user memories manually.
"""

from agno.db.postgres import PostgresDb
from agno.memory import MemoryManager, UserMemory
from rich.pretty import pprint

# ---------------------------------------------------------------------------
# Setup
# ---------------------------------------------------------------------------
db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"

# ---------------------------------------------------------------------------
# Create Memory Manager
# ---------------------------------------------------------------------------
memory = MemoryManager(db=PostgresDb(db_url=db_url))

# ---------------------------------------------------------------------------
# Run Memory Manager
# ---------------------------------------------------------------------------
if __name__ == "__main__":
    memory.add_user_memory(
        memory=UserMemory(memory="The user's name is John Doe", topics=["name"]),
    )
    print("Memories:")
    pprint(memory.get_user_memories())

    jane_doe_id = "jane_doe@example.com"
    print(f"\nUser: {jane_doe_id}")
    memory_id_1 = memory.add_user_memory(
        memory=UserMemory(memory="The user's name is Jane Doe", topics=["name"]),
        user_id=jane_doe_id,
    )
    memory_id_2 = memory.add_user_memory(
        memory=UserMemory(memory="She likes to play tennis", topics=["hobbies"]),
        user_id=jane_doe_id,
    )
    memories = memory.get_user_memories(user_id=jane_doe_id)
    print("Memories:")
    pprint(memories)

    print("\nDeleting memory")
    assert memory_id_2 is not None
    memory.delete_user_memory(user_id=jane_doe_id, memory_id=memory_id_2)
    print("Memory deleted\n")
    memories = memory.get_user_memories(user_id=jane_doe_id)
    print("Memories:")
    pprint(memories)

    print("\nReplacing memory")
    assert memory_id_1 is not None
    memory.replace_user_memory(
        memory_id=memory_id_1,
        memory=UserMemory(memory="The user's name is Jane Mary Doe", topics=["name"]),
        user_id=jane_doe_id,
    )
    print("Memory replaced")
    memories = memory.get_user_memories(user_id=jane_doe_id)
    print("Memories:")
    pprint(memories)
```

## Run the Example

<Steps>
  <Snippet file="create-venv-step.mdx" />

  <Step title="Install dependencies">
    ```bash theme={null}
    uv pip install -U agno psycopg-binary sqlalchemy
    ```
  </Step>

  <Snippet file="run-pgvector-step.mdx" />

  <Step title="Run the example">
    Save the code above as `standalone_memory.py`, then run:

    ```bash theme={null}
    python standalone_memory.py
    ```
  </Step>
</Steps>

Full source: [cookbook/11\_memory/memory\_manager/01\_standalone\_memory.py](https://github.com/agno-agi/agno/blob/main/cookbook/11_memory/memory_manager/01_standalone_memory.py)
