from morphik import Morphikdb = Morphik()# Perform operationsdoc = db.ingest_text("Sample content")# Close the session when donedb.close()
import asynciofrom morphik import AsyncMorphikasync def main(): db = AsyncMorphik() # Perform operations doc = await db.ingest_text("Sample content") # Close the client when done await db.close()asyncio.run(main())
Context Manager Alternative
Instead of manually calling close(), you can use the Morphik client as a context manager:
Sync
Async
from morphik import Morphikwith Morphik() as db: doc = db.ingest_text("Sample content") # Session is automatically closed when exiting the with block
from morphik import AsyncMorphikasync with AsyncMorphik() as db: doc = await db.ingest_text("Sample content") # Client is automatically closed when exiting the with block