Usage
from morphik import Morphik
# Without authentication
db = Morphik()
# With authentication
db = Morphik("morphik://owner_id:token@api.morphik.ai")
from morphik import Morphik
# Without authentication
db = Morphik()
# With authentication
db = Morphik("morphik://owner_id:token@api.morphik.ai")
from morphik import AsyncMorphik
# Without authentication
async with AsyncMorphik() as db:
doc = await db.ingest_text("Sample content")
# With authentication
async with AsyncMorphik("morphik://owner_id:token@api.morphik.ai") as db:
doc = await db.ingest_text("Sample content")
User and Folder Scoping
Morphik supports organizing and isolating data by user and folder. This provides a way to build multi-tenant applications and organize documents across projects.
Quick Overview
# Folder scoping - organize by project or category
folder = db.create_folder("project_x")
doc = folder.ingest_text("This document belongs to Project X")
# User scoping - isolate data by end user
user_scope = db.signin("user123")
doc = user_scope.ingest_text("This belongs to user123 only")
# Combined scoping - organize by both user and folder
user_folder_scope = folder.signin("user123")
doc = user_folder_scope.ingest_text("This belongs to user123 in project_x")
# Folder scoping - organize by project or category
folder = db.create_folder("project_x")
doc = folder.ingest_text("This document belongs to Project X")
# User scoping - isolate data by end user
user_scope = db.signin("user123")
doc = user_scope.ingest_text("This belongs to user123 only")
# Combined scoping - organize by both user and folder
user_folder_scope = folder.signin("user123")
doc = user_folder_scope.ingest_text("This belongs to user123 in project_x")
# Folder scoping - organize by project or category
folder = db.create_folder("project_x")
doc = await folder.ingest_text("This document belongs to Project X")
# User scoping - isolate data by end user
user_scope = db.signin("user123")
doc = await user_scope.ingest_text("This belongs to user123 only")
# Combined scoping - organize by both user and folder
user_folder_scope = folder.signin("user123")
doc = await user_folder_scope.ingest_text("This belongs to user123 in project_x")
For detailed documentation and examples:
Constructor
Both clients share the same constructor parameters:
Morphik(uri: Optional[str] = None, timeout: int = 30, is_local: bool = False)
Morphik(uri: Optional[str] = None, timeout: int = 30, is_local: bool = False)
AsyncMorphik(uri: Optional[str] = None, timeout: int = 30, is_local: bool = False)
Parameters
uri
(str, optional): Morphik URI in format “morphik://<owner_id>:<token>@<host>”. If not provided, connects to http://localhost:8000 without authentication.
timeout
(int, optional): Request timeout in seconds. Defaults to 30.
is_local
(bool, optional): Whether connecting to local development server. Defaults to False.
Methods
Morphik provides the following methods. Each method page includes both synchronous and asynchronous versions.
Document Operations
Knowledge Graph Operations
Cache Operations
Client Management
Context Manager
Using the Morphik client as a context manager ensures that resources are properly closed when the context exits.
with Morphik() as db:
doc = db.ingest_text("Sample content")
with Morphik() as db:
doc = db.ingest_text("Sample content")
async with AsyncMorphik() as db:
doc = await db.ingest_text("Sample content")