← Back

Connect Your Python Backend to Agent & LLM Analytics

Overview

Use the REST API to connect your website from a Python backend. Please contact us if you need help.

Step 1: Start Tracking Visits

Paste in this function that makes an HTTP request to the REST API with your project's access token and detail about an incoming pageview request.

async def track_visit_in_dark_visitors(request):
    try:
        async with aiohttp.ClientSession() as session:
            await session.post(
                "https://api.darkvisitors.com/visits",
                headers={
                    "Authorization": "Bearer YOUR_ACCESS_TOKEN",
                    "Content-Type": "application/json",
                },
                json={
                    "request_path": request.url.path,
                    "request_method": request.method,
                    "request_headers": dict(request.headers),
                }
            )
    except Exception:
        pass

In the endpoints where you serve your pages, call the function for each incoming pageview request.

asyncio.create_task(track_visit_in_dark_visitors(request))

Tips

Step 2: Test Your Integration

If your website is correctly connected, you should see visits from the Dark Visitor agent in the realtime timeline within a few seconds.