-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdependencies.py
More file actions
35 lines (26 loc) · 1015 Bytes
/
Copy pathdependencies.py
File metadata and controls
35 lines (26 loc) · 1015 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"""FastAPI dependencies for the Notion integration."""
import os
from collections.abc import AsyncGenerator
import httpx
from fastapi import Depends, HTTPException, status
from app.core.integrations.notion.client import AsyncNotionClient
# * Global httpx client for connection pooling
_httpx_client = httpx.AsyncClient()
async def get_notion_token() -> str:
"""Retrieves the Notion API token from environment variables."""
token = os.getenv("NOTION_API_TOKEN")
if not token:
raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
detail="NOTION_API_TOKEN is not set in environment variables.",
)
return token
async def get_notion_client(
token: str = Depends(get_notion_token),
) -> AsyncGenerator[AsyncNotionClient, None]:
"""
FastAPI dependency to get an instance of the AsyncNotionClient.
Yields:
An instance of the AsyncNotionClient.
"""
yield AsyncNotionClient(token=token, client=_httpx_client)