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
+8
View File
@@ -0,0 +1,8 @@
# async def main():
# instance = NotionOrm.repo.pages()
# create = await instance.CreatePage()\
# .set_parent("page_id", "2a564c9be67881a185c1c5d9133b9b1c")\
# .set_title("Name", "Teste abc")\
# .set_children("heading_1", "Teste")\
# .call()
# return create
+22
View File
@@ -0,0 +1,22 @@
import sys, os, asyncio
sys.path.append(
os.path.abspath(
os.path.join(
os.path.dirname(__file__), '..', '..', '..', '..', '..', '..', '..'
)
)
)
from src.utils.pprint import pprint
from src.integrations.notion.orm.repositories.pages.GetPage import GetPage
async def main():
instance = GetPage()
search = await instance\
.set_database(name="accounts")\
.set_pageid("0db2806f-b365-4327-919d-afbd1943f2ad")\
.select("Name")
#.call(True)
return search
test = await main()
pprint(test)
+21
View File
@@ -0,0 +1,21 @@
import sys, os, asyncio
sys.path.append(
os.path.abspath(
os.path.join(
os.path.dirname(__file__), '..', '..', '..', '..', '..', '..', '..'
)
)
)
from src.utils.pprint import pprint
from src.integrations.notion.orm.repositories.pages.GetPageProperty import GetPageProperty
async def main():
instance = GetPageProperty()
search = await instance\
.set_pageid("0db2806f-b365-4327-919d-afbd1943f2ad")\
.set_propname("Movements")\
.call()
return search
test = await main()
pprint(test)
View File
+176
View File
@@ -0,0 +1,176 @@
from typing import Literal, Any, Optional
from pydantic import validate_call
from ....schemas.responses.pages.Page import Page as _schmPage
from ....schemas.responses.errors.Error import Error as _schmError
from ....client import get_client as _get_client
from ...common.SetProperty import SetProperty as _setProperty
from ...parsers import Parser as _parser
class CreatePage:
def __init__(self) -> None:
self.data : dict[str, Any] = {
"properties": {}
}
self.set_property = _setProperty(self, self.data["properties"])
@validate_call
def set_parent(self,
type : Literal["page_id", "database_id"],
parent_id : str
):
self.data["parent"] = {
type : parent_id
}
return self
@validate_call
def set_template(self,
type : Literal["default", "template_id"],
template_id : Optional[str] = None
):
if type == "template_id":
if template_id is None:
raise TypeError("Template Type was set to 'template_id' but no ID was provided")
self.data["template"] = {
"type": type,
"template_id": template_id
}
return self
self.data["template"] = {
"type": type
}
return self
@validate_call
def set_title(self,
prop_name : Optional[str],
prop_value : Optional[str]
):
if prop_value is None:
return self
if self.data["parent"].get("page_id"):
self.data["properties"] = {
"title": [
{
"text": {
"content": prop_value
}
}
]
}
return self
self.data["properties"][prop_name] = {
"title": [
{
"text": {
"content": prop_value
}
}
]
}
return self
@validate_call
def set_icon(self,
type: Literal["external"],
content: Optional[str]
):
if content is None:
return self
match type:
case "external":
self.data["icon"] = {
"external": {
"url": str(content)
}
}
return self
@validate_call
def set_children(self,
type: Literal["heading_1", "paragraph"],
content: Any
):
if self.data.get("children") is None:
self.data["children"] = []
match type:
case "heading_1":
self.data["children"].append(
{
"object": "block",
"type": "heading_1",
"heading_1": {
"rich_text": [
{
"type": "text",
"text": {
"content": content
}
}
]
}
}
)
case "paragraph":
self.data["children"].append(
{
"object": "block",
"type": "paragraph",
"paragraph": {
"rich_text": [
{
"type": "text",
"text": {
"content": content
}
}
]
}
}
)
return self
async def call(self,
parse_properties : bool = True
) -> _schmPage:
client = _get_client()
create = await client.pages.create(
json_data = self.data
)
if create['object'] == 'error':
error = _schmError(**create)
raise KeyError(error.__dict__)
if parse_properties:
properties = _parser.page_props(page = create)
create["properties"] = properties
return _schmPage(**create)
__all__ = ["CreatePage"]
+92
View File
@@ -0,0 +1,92 @@
from typing import Dict, Any, Optional, TypeVar, Generic
from ....schemas.responses.pages.Page import Page as _schmPage
from ....schemas.responses.errors.Error import Error as _schmError
from ....client import get_client as _get_client
from ...mapping.database import NotionDatabase as _NotionDatabase
from ...mapping import Mapping as _map
from ...parsers import Parser as _parser
TDB = TypeVar('TDB', bound =_NotionDatabase)
class GetPage(Generic[TDB]):
def __init__(self,
database_id : Optional[str] = None,
generic_response : bool = False
) -> None:
self._database_id : Optional[str] = database_id
self._generic_response = generic_response
self._pageid : str
def set_pageid(self,
id : str
) -> 'GetPage[TDB]':
self._pageid = id
return self
def set_database(self,
id : str
) -> 'GetPage[TDB]':
self._database_id = id
return self
async def select(self,
property : str
) -> Optional[Any]:
client = _get_client()
page : Dict[str, Any] = await client.pages.get(
page_id = self._pageid
)
if page['object'] == 'error':
error = _schmError(**page)
raise KeyError(error.__dict__)
page["properties"] = _parser.page_props(page = page)
if page["properties"] is None:
return None
allprops = page["properties"]
return allprops[property]
async def call(self,
map_properties : bool = True,
raw_response : bool = False
) -> _schmPage[TDB]:
client = _get_client()
page : Dict[str, Any] = await client.pages.get(
page_id = self._pageid
)
if page['object'] == 'error':
error = _schmError(**page)
raise KeyError(error.__dict__)
if not raw_response:
if map_properties and self._database_id:
parser = None
if not self._generic_response:
# Tenta pegar parser do registry
parser = _map.registry.get_parser(
database_id = self._database_id,
page_parser = _parser.page_props
)
# Fallback: se database não registrada, usa parser genérico
if not parser:
parser = _parser.page_props
mapped_properties = parser(page = page)
page["properties"] = mapped_properties
elif map_properties:
page["properties"] = _parser.page_props(page = page)
return _schmPage(**page)
+63
View File
@@ -0,0 +1,63 @@
from pydantic import validate_call
from typing import Dict, Any, Optional
from ....schemas.responses.errors.Error import Error as _schmError
from ....client import get_client as _get_client
from ...parsers.PageProperties import PageProperties as _PageProperties
class GetPageProperty:
"""
# CUIDADO AO UTILIZAR!!
### [Bug Conhecido](https://community.latenode.com/t/notion-api-relation-property-showing-empty-array-despite-ui-showing-connected-pages/25780) na API do Notion impede retornos confiáveis em propriedades paginadas
Ultimo teste : 2026-01-10
"""
def __init__(self) -> None:
self._pageid : str
self._propname : str
@validate_call
def set_pageid(self,
id : str
):
self._pageid = id
return self
@validate_call
def set_propname(self,
name : str
):
self._propname = name
return self
async def call(self,
raw_response : bool = False
) -> Optional[Dict[str, Any]]:
client = _get_client()
getprop = await client.pages.get_property(
page_id = self._pageid,
property_name = self._propname
)
if getprop['object'] == 'error':
error = _schmError(**getprop)
raise KeyError(error.__dict__)
prop_data = getprop.get("results")
if getprop.get("object") == "property_item":
prop_data = [getprop]
if not prop_data:
return None
if not raw_response:
result = _PageProperties.parse(
page = prop_data[0]
)
result = prop_data[0]
return result
+30
View File
@@ -0,0 +1,30 @@
from typing import Optional, Generic, TypeVar
from ...mapping.database import NotionDatabase as _NotionDatabase
from .CreatePage import CreatePage as _CreatePage
from .GetPage import GetPage as _GetPage
from .GetPageProperty import GetPageProperty as _GetPageProperty
TDB = TypeVar('TDB', bound = _NotionDatabase)
class _Pages(Generic[TDB]):
def __init__(self,
database_id : Optional[str] = None,
generic_response : bool = False
) -> None:
self._database_id = database_id
self._generic_response = generic_response
self.CreatePage = _CreatePage
self.GetPageProperty = _GetPageProperty
@property
def GetPage(self) -> _GetPage:
return _GetPage(
database_id = self._database_id,
generic_response = self._generic_response
)
Pages = _Pages()
__all__ = ["Pages", "_Pages"]