- Sync
- Async
Parameters
NoneReturns
NoneExamples
- Sync
- Async
Context Manager Alternative
Instead of manually callingclose(), you can use the Morphik client as a context manager:
- Sync
- Async
Close the HTTP session or client
def close() -> None
async def close() -> None
from morphik import Morphik
db = Morphik()
# Perform operations
doc = db.ingest_text("Sample content")
# Close the session when done
db.close()
import asyncio
from morphik import AsyncMorphik
async def main():
db = AsyncMorphik()
# Perform operations
doc = await db.ingest_text("Sample content")
# Close the client when done
await db.close()
asyncio.run(main())
close(), you can use the Morphik client as a context manager:
from morphik import Morphik
with Morphik() as db:
doc = db.ingest_text("Sample content")
# Session is automatically closed when exiting the with block
from morphik import AsyncMorphik
async with AsyncMorphik() as db:
doc = await db.ingest_text("Sample content")
# Client is automatically closed when exiting the with block
Was this page helpful?