1212
1313### A Notion API wrapper for Python (In Development)
1414
15- Simple to use and easy to understand API wrapper for Notion.so Curently in development and
15+ Simple to use and easy to understand API wrapper for Notion.so Curently in development and
1616supports the following features:
17+
17181 . Create a new database
18192 . Get a database
1920
21+ [ ![ forthebadge made-with-python] ( http://ForTheBadge.com/images/badges/made-with-python.svg )] ( https://www.python.org/ )
22+
2023## Installation
24+
2125` poetry add pynotionclient `
2226
2327` pip install pynotionclient `
2428
2529## Usage
30+
2631``` python
2732from pynotionclient import PyNotion
2833from examples.config import base_config
@@ -91,6 +96,7 @@ response_filter_payload: NotionDatabaseResponseSchema = py_notion_client.databas
9196> properties: https://developers.notion.com/reference/database
9297
9398#### 3. Creating a database
99+
94100``` python
95101from dotenv import load_dotenv
96102
@@ -114,73 +120,74 @@ from pynotionclient.schema.database import (
114120 NumberFormats,
115121 NumberFormatConfiguration,
116122 DatabasePropertyConfiguration,
117- )
123+ )
118124
119125load_dotenv()
120126py_notion_client = PyNotion(token = base_config.notion_secret_token)
121127
122128# # Create database payload
123129parent_payload = ParentConfiguration(
124- type = " page_id" , page_id = base_config.page_id
125- ) # The parent is the page where the database will be created.
130+ type = " page_id" , page_id = base_config.page_id
131+ ) # The parent is the page where the database will be created.
126132icon_payload = IconConfiguration(
127- type = " emoji" , emoji = " 🎮"
128- ) # The icon is the icon that will be displayed on the database.
133+ type = " emoji" , emoji = " 🎮"
134+ ) # The icon is the icon that will be displayed on the database.
129135text = TextConfiguration(
130- content = " Game"
131- ) # The text is the text that will be displayed as the title of the database.
136+ content = " Game"
137+ ) # The text is the text that will be displayed as the title of the database.
132138content = ContentConfiguration(
133- type = " text" , plain_text = " Game" , href = " https://www.google.com" , text = text
134- ) # The content has other info's of the title.
139+ type = " text" , plain_text = " Game" , href = " https://www.google.com" , text = text
140+ ) # The content has other info's of the title.
135141
136142# Cover schema
137143cover = CoverConfiguration(
138- type = " external" , external = ExternalConfiguration(url = " https://www.google.com" )
139- )
144+ type = " external" , external = ExternalConfiguration(url = " https://www.google.com" )
145+ )
140146
141147# # Forming select options schema
142148properties = {
143- " Name" : TitleConfiguration().dict(),
144- " Description" : RichTextConfiguration().dict(),
145- " In stock" : CheckboxConfiguration().dict(),
146- " Food Group" : SelectConfiguration(
147- select = SelecOptionsListConfig(
148- options = [
149- SelectOptionsConfiguration(color = " green" , name = " Code" ),
150- SelectOptionsConfiguration(color = " red" , name = " Game" ),
151- ],
152- )
153- ).dict(),
154- " Cusines" : MultiSelectConfiguration(
155- multi_select = SelecOptionsListConfig(
156- options = [
157- SelectOptionsConfiguration(color = " green" , name = " Code" ),
158- SelectOptionsConfiguration(color = " red" , name = " Game" ),
159- ],
160- )
161- ).dict(),
162- " Price" : NumberConfiguration(
163- number = NumberFormatConfiguration(
164- format = NumberFormats.NUMBER_WITH_COMMAS ,
165- ),
166- ).dict(),
167- }
149+ " Name" : TitleConfiguration().dict(),
150+ " Description" : RichTextConfiguration().dict(),
151+ " In stock" : CheckboxConfiguration().dict(),
152+ " Food Group" : SelectConfiguration(
153+ select = SelecOptionsListConfig(
154+ options = [
155+ SelectOptionsConfiguration(color = " green" , name = " Code" ),
156+ SelectOptionsConfiguration(color = " red" , name = " Game" ),
157+ ],
158+ )
159+ ).dict(),
160+ " Cusines" : MultiSelectConfiguration(
161+ multi_select = SelecOptionsListConfig(
162+ options = [
163+ SelectOptionsConfiguration(color = " green" , name = " Code" ),
164+ SelectOptionsConfiguration(color = " red" , name = " Game" ),
165+ ],
166+ )
167+ ).dict(),
168+ " Price" : NumberConfiguration(
169+ number = NumberFormatConfiguration(
170+ format = NumberFormats.NUMBER_WITH_COMMAS ,
171+ ),
172+ ).dict(),
173+ }
168174print (properties)
169175create_database_payload = DatabasePropertyConfiguration(
170- title = [content],
171- cover = cover,
172- parent = parent_payload,
173- icon = icon_payload,
174- properties = properties,
175- )
176+ title = [content],
177+ cover = cover,
178+ parent = parent_payload,
179+ icon = icon_payload,
180+ properties = properties,
181+ )
176182
177183response = py_notion_client.database.create_database(
178- payload = create_database_payload,
179- )
184+ payload = create_database_payload,
185+ )
180186
181187print (response.json())
182188```
183189
184190## Contributing
185191
186- Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
192+ Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
193+
0 commit comments