Finaliza ajustes para iniciar Repositorio Git do SDK de Integração do Notion separado do meu projeto original

---

- Cria singleton de `client` com func `configure` para inicializar e `get_instance` para buscar instância do client;
- Ajusta clients para buscar headers vindo do pai `client` e fixa versão legacy no client de databases;
- Adiciona inicialização de `client` no init do projeto com api_token e api_version informados pelo usuário;
- Altera `NotionConfig` para inserir `database_id` no lugar de `database_name`;
- Altera sistema para receber `database_id` no lugar de `database_name`;
- Altera tipo de `properties` em `schemas.responses.pages.Page` de `Union[Dict[str, Any]], TDB` para `Union[Any, TDB]` para resolver reclamações de type hint;
- Adiciona param `generic_response` no init de `client` e nos clients e databases e pages para pular uso de mapping ao usar `.generic`;
- Adiciona param `raw_response` para pular parser e mappings e retornar resposta original da api;
- Finaliza `types` com subpastas para importações mas com init mãe vazio para evitar dependência circular e permitir uso de `notion.types.` pelo usuário;
- Remove importações do projeto original não relacionadas com o SDK;
- Adiciona param `timezone` na func `start_date` em `orm.common.SetProperty` que antes vinha do env, para posteriormente puxar da init da integração;
- Monta `LICENSE`, `README.md` e `pyproject.toml` base simples para commit inicial do projeto permitindo build de pacote;

---
This commit is contained in:
2026-01-20 22:26:39 -03:00
commit aff0446458
72 changed files with 2910 additions and 0 deletions
+75
View File
@@ -0,0 +1,75 @@
from typing import Dict, Optional
from .blocks import Blocks
from .pages import Pages
from .databases import Databases
class Client:
"Client singleton da API Notion"
_headers : Optional[Dict[str, str]] = None
_instance : Optional['Client'] = None
def __init__(self):
self._blocks = None
self._pages = None
self._databases = None
@classmethod
def configure(cls, headers : Dict[str, str]):
"Configura o client com headers"
cls._headers = headers
@classmethod
def get_instance(cls) -> 'Client':
"Retorna a instância configurada"
if cls._instance is None:
cls._instance = Client()
return cls._instance
@property
def blocks(self) -> Blocks:
if self._blocks is None:
if Client._headers is None:
raise RuntimeError("Client não configurado. Instancie NotionIntegration primeiro.")
self._blocks = Blocks(Client._headers)
return self._blocks
@property
def pages(self) -> Pages:
if self._pages is None:
if Client._headers is None:
raise RuntimeError("Client não configurado. Instancie NotionIntegration primeiro.")
self._pages = Pages(Client._headers)
return self._pages
@property
def databases(self) -> Databases:
if self._databases is None:
if Client._headers is None:
raise RuntimeError("Client não configurado. Instancie NotionIntegration primeiro.")
self._databases = Databases(Client._headers)
return self._databases
def get_client() -> Client:
return Client.get_instance()
__all__ = ["Client", "get_client"]
+24
View File
@@ -0,0 +1,24 @@
import httpx
from typing import Dict
class Blocks:
"Reference: https://developers.notion.com/reference/retrieve-a-block"
def __init__(self, headers : Dict[str, str]):
self._headers = headers
async def get_children(self, page_id : str):
"Busca pelos blocos de uma página"
async with httpx.AsyncClient(timeout=httpx.Timeout(30.0)) as client:
response = await client.get(
f'https://api.notion.com/v1/blocks/{page_id}/children',
headers = self._headers
)
return response.json()
__all__ = ["Blocks"]
+64
View File
@@ -0,0 +1,64 @@
import httpx
from typing import Dict
class Databases:
def __init__(self, headers : Dict[str, str]):
self._headers = {**headers, "Notion-Version": "2022-06-28"}
async def get(self, database_id):
"Buscar informações de um Banco de Dados"
async with httpx.AsyncClient(timeout=httpx.Timeout(30.0)) as client:
response = await client.get(
f'https://api.notion.com/v1/databases/{database_id}',
headers = self._headers
)
return response.json()
async def query(self, database_id, json_data = {}):
"Buscar as Páginas de um Banco de Dados"
async with httpx.AsyncClient(timeout=httpx.Timeout(30.0)) as client:
response = await client.post(
f'https://api.notion.com/v1/databases/{database_id}/query',
headers = self._headers,
json = json_data
)
return response.json()
async def query_propriety(self, database_id, propriety_type, json_data = {}):
"Buscar as Páginas de um Banco de Dados filtrando por uma Propriedade"
async with httpx.AsyncClient(timeout=httpx.Timeout(30.0)) as client:
response = await client.post(
f'https://api.notion.com/v1/databases/{database_id}/query?filter_properties={propriety_type}',
headers = self._headers,
json = json_data
)
return response.json()
async def update(self, database_id, json_data):
"Atualiza as informações sobre um Banco de Dados"
async with httpx.AsyncClient(timeout=httpx.Timeout(30.0)) as client:
response = await client.patch(
f'https://api.notion.com/v1/databases/{database_id}',
headers = self._headers,
json = json_data
)
return response.json()
__all__ = ["Databases"]
+73
View File
@@ -0,0 +1,73 @@
import httpx
from typing import Dict, Any
class Pages:
def __init__(self, headers : Dict[str, str]):
self._headers = headers
async def get(self,
page_id : str
):
"Buscar informações de uma Página"
async with httpx.AsyncClient(timeout=httpx.Timeout(30.0)) as client:
response = await client.get(
f'https://api.notion.com/v1/pages/{page_id}',
headers = self._headers
)
return response.json()
async def get_property(self,
page_id : str,
property_name : str
):
"Buscar por informações de uma Propriedade em uma Página"
async with httpx.AsyncClient(timeout=httpx.Timeout(30.0)) as client:
response = await client.get(
f'https://api.notion.com/v1/pages/{page_id}/properties/{property_name}',
headers = self._headers
)
return response.json()
async def update_properties(self,
page_id : str,
json_data : Dict[str, Any]
):
"Atualiza as Propriedades de uma Página"
async with httpx.AsyncClient(timeout=httpx.Timeout(30.0)) as client:
response = await client.patch(
f'https://api.notion.com/v1/pages/{page_id}',
headers = self._headers,
json=json_data
)
return response.json()
async def create(self,
json_data : Dict[str, Any]
):
"Criar uma nova Página"
async with httpx.AsyncClient(timeout=httpx.Timeout(30.0)) as client:
response = await client.post(
f'https://api.notion.com/v1/pages',
headers = self._headers,
json = json_data
)
return response.json()
__all__ = ["Pages"]