Install and authenticate
Install and authenticate
Install the makra package, provide an API key, and reuse one client for the lifetime of your application.
Requirements
The Python SDK requires Python 3.9 or newer. Version 0.0.4 depends on httpx and supports synchronous and asynchronous clients.
Install it with pip install makra in the Python environment used by your application.
Provide the API key
The SDK reads MAKRA_API_KEY when no key is passed to the constructor. Read the value in your process environment and fail before making a request if it is missing.
import os
from makra import Makra
api_key = os.environ.get("MAKRA_API_KEY")
if not api_key:
raise RuntimeError("MAKRA_API_KEY is required")
with Makra(api_key) as client:
health = client.ping()
print(health)
Passing a key directly takes precedence over the environment. The SDK also accepts MAKRA_BASE_URL, MAKRA_TIMEOUT, and MAKRA_MAX_RETRIES. Explicit constructor arguments take precedence over those values.
Do not put an API key in source code, logs, example output, URLs, or custom headers. The client sends it as Api-Key and prevents default_headers from overriding that header.
Reuse and close the client
Makra owns an HTTP connection pool. Create one client per application lifetime or per well-defined worker lifetime. Use a context manager for scripts.
from makra import Makra
with Makra() as client:
gateway = client.ping()
storage = client.ready()
print(gateway, storage)
ping() checks whether the API gateway is reachable. ready() also checks the result-storage dependency. Neither call proves that a target website is reachable or extractable.
For asynchronous applications, use AsyncMakra and an async context manager.
import asyncio
from makra import AsyncMakra
async def main() -> None:
async with AsyncMakra() as client:
print(await client.ready())
asyncio.run(main())
If no API key is available, the SDK falls back to a development placeholder. The hosted API will reject that placeholder. Treat a successful local construction as configuration parsing, not authentication proof.
Next, run your first extraction.