sdk-notion 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. sdk_notion-0.1.0/LICENSE +9 -0
  2. sdk_notion-0.1.0/PKG-INFO +389 -0
  3. sdk_notion-0.1.0/README.md +374 -0
  4. sdk_notion-0.1.0/notion/__init__.py +54 -0
  5. sdk_notion-0.1.0/notion/auth/__init__.py +22 -0
  6. sdk_notion-0.1.0/notion/client/__init__.py +75 -0
  7. sdk_notion-0.1.0/notion/client/blocks.py +24 -0
  8. sdk_notion-0.1.0/notion/client/databases.py +64 -0
  9. sdk_notion-0.1.0/notion/client/pages.py +73 -0
  10. sdk_notion-0.1.0/notion/orm/__init__.py +17 -0
  11. sdk_notion-0.1.0/notion/orm/accessors/PageProperty.py +106 -0
  12. sdk_notion-0.1.0/notion/orm/accessors/__init__.py +9 -0
  13. sdk_notion-0.1.0/notion/orm/common/QueryFilter.py +541 -0
  14. sdk_notion-0.1.0/notion/orm/common/QuerySort.py +72 -0
  15. sdk_notion-0.1.0/notion/orm/common/SetProperty.py +233 -0
  16. sdk_notion-0.1.0/notion/orm/common/__init__.py +13 -0
  17. sdk_notion-0.1.0/notion/orm/config/__init__.py +27 -0
  18. sdk_notion-0.1.0/notion/orm/extrators/Properties.py +146 -0
  19. sdk_notion-0.1.0/notion/orm/extrators/__init__.py +8 -0
  20. sdk_notion-0.1.0/notion/orm/mapping/__init__.py +12 -0
  21. sdk_notion-0.1.0/notion/orm/mapping/database.py +199 -0
  22. sdk_notion-0.1.0/notion/orm/mapping/registry.py +92 -0
  23. sdk_notion-0.1.0/notion/orm/parsers/PageProperties.py +36 -0
  24. sdk_notion-0.1.0/notion/orm/parsers/__init__.py +9 -0
  25. sdk_notion-0.1.0/notion/orm/repositories/__init__.py +26 -0
  26. sdk_notion-0.1.0/notion/orm/repositories/databases/CreateDatabasePage.py +93 -0
  27. sdk_notion-0.1.0/notion/orm/repositories/databases/SearchPage.py +101 -0
  28. sdk_notion-0.1.0/notion/orm/repositories/databases/SearchPageProperty.py +94 -0
  29. sdk_notion-0.1.0/notion/orm/repositories/databases/__init__.py +57 -0
  30. sdk_notion-0.1.0/notion/orm/repositories/pages/CreatePage.py +176 -0
  31. sdk_notion-0.1.0/notion/orm/repositories/pages/GetPage.py +92 -0
  32. sdk_notion-0.1.0/notion/orm/repositories/pages/GetPageProperty.py +65 -0
  33. sdk_notion-0.1.0/notion/orm/repositories/pages/__init__.py +30 -0
  34. sdk_notion-0.1.0/notion/schemas/__init__.py +9 -0
  35. sdk_notion-0.1.0/notion/schemas/dto.py +13 -0
  36. sdk_notion-0.1.0/notion/schemas/orm/__init__.py +7 -0
  37. sdk_notion-0.1.0/notion/schemas/orm/database/DatabasesContainer.py +3 -0
  38. sdk_notion-0.1.0/notion/schemas/orm/database/SearchPageProperty.py +8 -0
  39. sdk_notion-0.1.0/notion/schemas/orm/database/__init__.py +9 -0
  40. sdk_notion-0.1.0/notion/schemas/orm/properties/RichText.py +9 -0
  41. sdk_notion-0.1.0/notion/schemas/orm/properties/__init__.py +7 -0
  42. sdk_notion-0.1.0/notion/schemas/responses/__init__.py +13 -0
  43. sdk_notion-0.1.0/notion/schemas/responses/databases/Query.py +15 -0
  44. sdk_notion-0.1.0/notion/schemas/responses/databases/__init__.py +7 -0
  45. sdk_notion-0.1.0/notion/schemas/responses/errors/Error.py +8 -0
  46. sdk_notion-0.1.0/notion/schemas/responses/errors/__init__.py +7 -0
  47. sdk_notion-0.1.0/notion/schemas/responses/pages/Page.py +24 -0
  48. sdk_notion-0.1.0/notion/schemas/responses/pages/Parent.py +9 -0
  49. sdk_notion-0.1.0/notion/schemas/responses/pages/__init__.py +9 -0
  50. sdk_notion-0.1.0/notion/schemas/responses/pages/properties/RichText.py +23 -0
  51. sdk_notion-0.1.0/notion/schemas/responses/pages/properties/__init__.py +7 -0
  52. sdk_notion-0.1.0/notion/schemas/responses/users/Bot.py +11 -0
  53. sdk_notion-0.1.0/notion/schemas/responses/users/Person.py +11 -0
  54. sdk_notion-0.1.0/notion/schemas/responses/users/User.py +6 -0
  55. sdk_notion-0.1.0/notion/schemas/responses/users/__init__.py +13 -0
  56. sdk_notion-0.1.0/notion/schemas/responses/users/type/Bot.py +6 -0
  57. sdk_notion-0.1.0/notion/schemas/responses/users/type/Person.py +6 -0
  58. sdk_notion-0.1.0/notion/schemas/responses/users/type/__init__.py +9 -0
  59. sdk_notion-0.1.0/notion/types/__init__.py +0 -0
  60. sdk_notion-0.1.0/notion/types/orm/__init__.py +0 -0
  61. sdk_notion-0.1.0/notion/types/orm/databases/__init__.py +4 -0
  62. sdk_notion-0.1.0/notion/types/orm/properties/__init__.py +1 -0
  63. sdk_notion-0.1.0/notion/types/responses/__init__.py +0 -0
  64. sdk_notion-0.1.0/notion/types/responses/databases/__init__.py +1 -0
  65. sdk_notion-0.1.0/notion/types/responses/errors/__init__.py +1 -0
  66. sdk_notion-0.1.0/notion/types/responses/pages/__init__.py +2 -0
  67. sdk_notion-0.1.0/notion/types/responses/users/__init__.py +3 -0
  68. sdk_notion-0.1.0/pyproject.toml +26 -0
  69. sdk_notion-0.1.0/sdk_notion.egg-info/PKG-INFO +389 -0
  70. sdk_notion-0.1.0/sdk_notion.egg-info/SOURCES.txt +72 -0
  71. sdk_notion-0.1.0/sdk_notion.egg-info/dependency_links.txt +1 -0
  72. sdk_notion-0.1.0/sdk_notion.egg-info/requires.txt +2 -0
  73. sdk_notion-0.1.0/sdk_notion.egg-info/top_level.txt +1 -0
  74. sdk_notion-0.1.0/setup.cfg +4 -0
@@ -0,0 +1,9 @@
1
+ # MIT License
2
+
3
+ Copyright 2026 Eduardo Riguetto (kralot / riguettodev)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,389 @@
1
+ Metadata-Version: 2.4
2
+ Name: sdk-notion
3
+ Version: 0.1.0
4
+ Summary: Async Python SDK for the Notion API
5
+ Author: Eduardo Riguetto
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/riguettodev/sdk-notion
8
+ Project-URL: Repository, https://github.com/riguettodev/sdk-notion
9
+ Requires-Python: >=3.9
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Requires-Dist: httpx<1.0,>=0.25
13
+ Requires-Dist: pydantic<3.0,>=2.5
14
+ Dynamic: license-file
15
+
16
+ # Notion SDK
17
+
18
+ > **Beta Release** 🎉\
19
+ > Desenvolvido por [Eduardo Riguetto](https://riguetto.dev)
20
+
21
+ ## 🎯 Visão Geral
22
+
23
+ SDK Python moderno e type-safe para a API Notion, com foco em Developer Experience (DX) e autocomplete perfeito.
24
+
25
+ ---
26
+
27
+ ## ✨ Principais Features
28
+
29
+ ### 🔐 Autenticação Simplificada
30
+
31
+ - Configuração centralizada via `Notion()` com suporte a múltiplas versões da API
32
+ - Suporte para versões `legacy` (2022-06-28), `data_sources` (2025-09-03), ou personalizada
33
+ - Headers gerenciados automaticamente via singleton pattern
34
+
35
+ ### 🗄️ ORM Declarativo
36
+
37
+ - **Sistema de Mapeamento Declarativo**: Defina schemas uma única vez com `NotionDatabase`
38
+ - **Type Hints Perfeitos**: Autocomplete completo em IDEs (VSCode, PyCharm)
39
+ - **Transformers Customizáveis**: Processe propriedades do Notion conforme necessário
40
+ - **Validators Integrados**: Validação automática com Pydantic
41
+ - **Computed Fields**: Campos calculados automaticamente a partir de outros campos
42
+ - **Registry Global**: Acesso centralizado a todas as databases via `DatabaseRegistry`
43
+ - **Container Pattern**: Organize suas databases com `DatabasesContainer`
44
+
45
+ ### 📦 Repositories
46
+
47
+ **Pages:**
48
+
49
+ - `CreatePage` - Criação de páginas com fluent interface
50
+ - `GetPage` - Busca de páginas com mapeamento automático de schemas
51
+ - `GetPageProperty` - Acesso direto a propriedades específicas
52
+
53
+ **Databases:**
54
+
55
+ - `CreateDatabasePage` - Criação de páginas em databases com type safety
56
+ - `SearchPage` - Queries avançadas com filtros e ordenação
57
+ - `SearchPageProperty` - Busca de propriedades específicas em databases
58
+
59
+ ### 🎨 Fluent Interface
60
+
61
+ ```python
62
+ await notion.orm.repo.pages.CreatePage()\
63
+ .set_parent("database_id", "db_id")\
64
+ .set_title("Name", "My Page")\
65
+ .set_property.start_date("Date", datetime.now())\
66
+ .set_property.number("Count", 42)\
67
+ .call()
68
+ ```
69
+
70
+ ### 🔧 Features Avançadas
71
+
72
+ - **Generic Types**: Tipagem forte com Generic/TypeVars para autocomplete perfeito
73
+ - **Property System**: Sistema completo de setters para todos os tipos de propriedades
74
+ - **Query Builders**: Construtores fluentes para filtros (`QueryFilter`) e ordenação (`QuerySort`)
75
+ - **Property Extractors**: Extração automática de propriedades da API Notion
76
+ - **Property Parsers**: Parse inteligente de respostas com suporte a tipos complexos
77
+ - **Property Accessors**: Acesso tipado a propriedades de páginas
78
+ - **Configuração Global**: Timezone e outras configs definidas via `ORMConfig`
79
+ - **Singleton Pattern**: Client configurado globalmente, sem duplicação
80
+
81
+ ---
82
+
83
+ ## 🚀 Quick Start
84
+
85
+ ```python
86
+ from notion import Notion
87
+ from my_databases import MyContainer
88
+
89
+ # Configuração
90
+ notion: Notion[MyContainer] = Notion(
91
+ api_token="secret_...",
92
+ api_version="data_sources",
93
+ orm_container=MyContainer,
94
+ timezone="America/Sao_Paulo"
95
+ )
96
+
97
+ # Uso com autocomplete perfeito
98
+ con = notion.orm.repo.databases.container.tasks.SearchPage
99
+ result = await con\
100
+ .set_filter(
101
+ con.filter.checkbox("Done", "equals", False)
102
+ )\
103
+ .call()
104
+
105
+ # Acesso type-safe
106
+ for page in result.results:
107
+ print(page.properties.myproperty) # ← Autocomplete funciona!
108
+ ```
109
+
110
+ ---
111
+
112
+ ### 📦 Configurando seu ORM
113
+
114
+ #### 1. Defina seus Schemas
115
+
116
+ Crie schemas para suas databases do Notion usando `NotionDatabase`:
117
+
118
+ ```python
119
+ # my_databases/tasks.py
120
+
121
+ from notion.types.orm.databases import NotionDatabase
122
+ from pydantic import ConfigDict
123
+ from typing import Optional, List
124
+ from datetime import date, datetime
125
+ from decimal import Decimal
126
+
127
+ class TasksDb(NotionDatabase):
128
+
129
+ model_config = ConfigDict(title="Notion_Databases_TasksDb")
130
+
131
+ # Defina os campos do schema
132
+ title: Optional[str]
133
+ status: Optional[str]
134
+ priority: Optional[str]
135
+ tags: Optional[List[str]]
136
+ due_date: Optional[date]
137
+ assignee: Optional[str]
138
+ completed: bool = False
139
+ progress: Optional[int]
140
+ estimated_hours: Optional[Decimal]
141
+ actual_hours: Optional[Decimal]
142
+
143
+ # Campos computed (não vêm do Notion, são calculados)
144
+ is_overdue: Optional[bool] = None
145
+ total_cost: Optional[Decimal] = None
146
+
147
+ class NotionConfig:
148
+ # ID da sua database no Notion
149
+ database_id = "abc123def456"
150
+
151
+ # Mapeie campos Python → Campos Notion
152
+ mappings = {
153
+ "title": "Title",
154
+ "status": "Status",
155
+ "priority": "Priority",
156
+ "tags": "Tags",
157
+ "due_date": "Due Date",
158
+ "assignee": "Assignee",
159
+ "completed": "Completed",
160
+ "progress": "Progress",
161
+ "estimated_hours": "Estimated Hours",
162
+ "actual_hours": "Actual Hours"
163
+ }
164
+
165
+ # Transformers para processar valores
166
+ transformers = {
167
+ "status": lambda x: x["name"] if x else None,
168
+ "priority": lambda x: x["name"] if x else None,
169
+ "tags": lambda x: [t["name"] for t in x] if x else [],
170
+ "assignee": lambda x: x[0] if x else None,
171
+ "due_date": lambda x: x["start"] if x else None,
172
+ "estimated_hours": lambda x: Decimal(str(x)) if x else None,
173
+ "actual_hours": lambda x: Decimal(str(x)) if x else None
174
+ }
175
+
176
+ # Validators para garantir integridade dos dados
177
+ validators = {
178
+ "progress": lambda v: max(0, min(100, v)) if v else 0, # Entre 0-100
179
+ "estimated_hours": lambda v: v if v and v >= 0 else Decimal(0) # Não negativo
180
+ }
181
+
182
+ # Computed fields calculados automaticamente
183
+ computed = {
184
+ "is_overdue": lambda obj: (
185
+ obj.due_date < date.today() and not obj.completed
186
+ if obj.due_date else False
187
+ ),
188
+ "total_cost": lambda obj: (
189
+ obj.actual_hours * Decimal("50.00") # $50/hora
190
+ if obj.actual_hours else None
191
+ )
192
+ }
193
+ ```
194
+
195
+ #### 2. Crie seu Container
196
+
197
+ Organize todas as suas databases em um container:
198
+
199
+ ```python
200
+ # my_databases/__init__.py
201
+
202
+ from notion.types.orm.databases import Container, Registry, Client
203
+ from .tasks import TasksDb
204
+ from .projects import ProjectsDb # Outras databases...
205
+
206
+ class MyDatabasesContainer(Container):
207
+ """Container customizado com suas databases"""
208
+
209
+ def __init__(self):
210
+ # Registre todas as databases
211
+ Registry.register(TasksDb)
212
+ Registry.register(ProjectsDb)
213
+
214
+ # Configure acesso tipado
215
+ self.tasks: Client[TasksDb] = Client(TasksDb.id())
216
+ self.projects: Client[ProjectsDb] = Client(ProjectsDb.id())
217
+
218
+ # Singleton para uso direto
219
+ databases = MyDatabasesContainer()
220
+
221
+ __all__ = ["MyDatabasesContainer", "databases"]
222
+ ```
223
+
224
+ #### 3. Configure a Integração
225
+
226
+ No seu `main.py` ou arquivo de inicialização:
227
+
228
+ ```python
229
+ from notion import Notion
230
+ from my_databases import MyDatabasesContainer
231
+
232
+ # Configure com seu container
233
+ notion = Notion(
234
+ api_token="secret_...",
235
+ api_version="data_sources",
236
+ orm_container=MyDatabasesContainer,
237
+ timezone="America/Sao_Paulo"
238
+ )
239
+
240
+ # Agora você tem autocomplete perfeito!
241
+ con = notion.orm.repo.databases.container.tasks.SearchPage
242
+ tasks = await con\
243
+ .set_filter(
244
+ con.checkbox("Completed", "equals", False)
245
+ )\
246
+ .call()
247
+
248
+ # Acesso type-safe aos dados
249
+ for task in tasks.results:
250
+ print(f"📋 {task.properties.title}")
251
+ print(f"Status: {task.properties.status}")
252
+ print(f"Due: {task.properties.due_date}")
253
+ ```
254
+
255
+ ---
256
+
257
+ ## 📚 Client API
258
+
259
+ ### Pages
260
+
261
+ - `get(page_id)` - Buscar página por ID
262
+ - `get_property(page_id, property_id)` - Buscar propriedade específica
263
+ - `update_properties(page_id, properties)` - Atualizar propriedades de uma página
264
+ - `create(parent, properties)` - Criar nova página
265
+
266
+ ### Databases
267
+
268
+ - `get(database_id)` - Buscar informações de uma database
269
+ - `query(database_id, filter, sorts)` - Query com filtros e ordenação
270
+ - `query_property(database_id, property_id)` - Query propriedade específica
271
+ - `update(database_id, properties)` - Atualizar schema de database
272
+
273
+ ### Blocks
274
+
275
+ - `get_children(block_id)` - Buscar blocos filhos de um bloco/página
276
+
277
+ ---
278
+
279
+ ## 📖 Schemas Disponíveis
280
+
281
+ **Responses:**
282
+
283
+ - `pages.Page`, `pages.Parent` - Estruturas de páginas
284
+ - `databases.Query` - Resultados de queries
285
+ - `users.User`, `users.Person`, `users.Bot` - Informações de usuários
286
+ - `errors.Error` - Erros da API
287
+ - `pages.properties.RichText` - Propriedade rich text
288
+
289
+ **ORM:**
290
+
291
+ - `NotionDatabase` - Classe base para schemas customizados
292
+ - `DatabasesContainer` - Container para organização de databases
293
+ - `SearchPageProperty` - Schema para propriedades de busca
294
+ - `properties.RichText` - Rich text para ORM
295
+
296
+ **DTO:**
297
+
298
+ - Data Transfer Objects para comunicação interna
299
+
300
+ ---
301
+
302
+ ## 🏗️ Arquitetura
303
+
304
+ ```
305
+ notion/
306
+ ├── auth/ # Sistema de autenticação
307
+ ├── client/ # HTTP clients por endpoint
308
+ │ ├── blocks.py # Blocks API
309
+ │ ├── databases.py # Databases API
310
+ │ └── pages.py # Pages API
311
+ ├── orm/
312
+ │ ├── accessors/ # Acesso tipado a propriedades
313
+ │ ├── common/ # QueryFilter, QuerySort, SetProperty
314
+ │ ├── config/ # Configurações globais do ORM
315
+ │ ├── extractors/ # Extração de propriedades da API
316
+ │ ├── mapping/ # Sistema declarativo (NotionDatabase)
317
+ │ ├── parsers/ # Parse de respostas da API
318
+ │ └── repositories/ # Camada de repositórios
319
+ │ ├── databases/ # Repositórios de databases
320
+ │ └── pages/ # Repositórios de pages
321
+ ├── schemas/
322
+ │ ├── orm/ # Schemas do ORM
323
+ │ │ ├── database/ # DatabasesContainer, SearchPageProperty
324
+ │ │ └── properties/ # RichText e outros
325
+ │ └── responses/ # Schemas de respostas da API
326
+ │ ├── databases/ # Query
327
+ │ ├── errors/ # Error
328
+ │ ├── pages/ # Page, Parent, properties
329
+ │ └── users/ # User, Person, Bot
330
+ └── types/ # Type definitions e exports
331
+ ├── orm/ # Types do ORM
332
+ └── responses/ # Types de responses
333
+ ```
334
+
335
+ ---
336
+
337
+ ## 📋 Dependências
338
+
339
+ - Python >= 3.9
340
+ - httpx - Requests HTTP assíncronos
341
+ - pydantic >= 2.5 - Validação e serialização
342
+
343
+ ---
344
+
345
+ ## 🐛 Known Issues
346
+
347
+ - Suporte parcial a tipos de propriedades (em desenvolvimento contínuo)
348
+ - Documentação completa em progresso
349
+ - Alguns endpoints da API Notion ainda não implementados
350
+
351
+ ---
352
+
353
+ ## 🔮 Roadmap
354
+
355
+ - [ ] Support completo para Blocks API (criação e atualização)
356
+ - [ ] Suporte completo a todos os tipos de propriedades Notion
357
+ - [ ] Documentação completa com exemplos práticos
358
+ - [ ] Testes unitários e de integração
359
+ - [ ] Support para Comments API
360
+ - [ ] Cache system para reduzir chamadas à API
361
+ - [ ] Retry logic e rate limiting inteligente
362
+ - [ ] CLI para geração automática de schemas a partir de databases
363
+
364
+ ---
365
+
366
+ ## 📄 Licença
367
+
368
+ MIT License - Veja [LICENSE](LICENSE) para detalhes
369
+
370
+ ---
371
+
372
+ ## 🙏 Agradecimentos
373
+
374
+ Desenvolvido com ❤️ por [Eduardo Riguetto](https://riguetto.dev)
375
+
376
+ **Contribuições são bem-vindas!** Sinta-se livre para:
377
+
378
+ - 🐛 Reportar bugs via Issues
379
+ - 💡 Sugerir features
380
+ - 🔧 Abrir Pull Requests
381
+ - 📖 Melhorar a documentação
382
+
383
+ ---
384
+
385
+ ## 🔗 Links
386
+
387
+ - **GitHub**: [https://github.com/riguettodev/sdk-notion](https://github.com/riguettodev/sdk-notion)
388
+ - **PyPI**: [https://pypi.org/project/sdk-notion/](https://pypi.org/project/sdk-notion/)
389
+ - **Documentação**: (em breve)