11<img src =" assets/notion.png " alt =" Notion Logo " height =" 240 " width =" 240 " style =" display : block ; margin : auto " >
2- <br >
3- <hr >
4- <h1 style =" font-size : 50px ; margin : 0 ; padding : 0 " >PyNotion</h1 >
52
6- ![ PyPI - Downloads] ( https://img.shields.io/pypi/dm/pynotionclient?color=brightgreen&logo=pypi&style=for-the-badge )
7- ![ GitHub last commit] ( https://img.shields.io/github/last-commit/pythonhubdev/PyNotion?style=for-the-badge )
8- ![ GitHub] ( https://img.shields.io/github/license/pythonhubdev/PyNotion?color=brightgreen&style=for-the-badge )
9- ![ GitHub Workflow Status] ( https://img.shields.io/github/actions/workflow/status/Quantivio/PyNotion/formtting.yaml?style=for-the-badge )
10- ![ Code Style] ( https://img.shields.io/static/v1?label=CodeStyle&message=Black&color=%3CCOLOR%3E&style=for-the-badge )
3+ ---
114
12- PyNotion is a simple and intuitive Python library for accessing the Notion API. With PyNotion, you can easily integrate
13- and automate Notion tasks within your Python projects.
5+ <h1 style =" font-size : 50px ; text-align : center ; margin : 0 ; padding : 0 " >PyNotion</h1 >
146
15- ** Please note that PyNotion is currently under development and may not yet be suitable for production use.**
7+ <div style =" text-align : center ;" >
8+ <a href =" https://pypi.org/project/pynotionclient/ " ><img alt =" PyPI - Downloads " src =" https://img.shields.io/pypi/dm/pynotionclient?color=brightgreen&logo=pypi&style=for-the-badge " ></a >
9+ <a href =" https://github.com/pythonhubdev/PyNotion/commits/main " ><img alt =" GitHub last commit " src =" https://img.shields.io/github/last-commit/pythonhubdev/PyNotion?style=for-the-badge " ></a >
10+ <a href =" https://github.com/pythonhubdev/PyNotion/blob/main/LICENSE " ><img alt =" GitHub license " src =" https://img.shields.io/github/license/pythonhubdev/PyNotion?color=brightgreen&style=for-the-badge " ></a >
11+ <a href =" https://github.com/Quantivio/PyNotion/actions " ><img alt =" GitHub Actions Workflow Status " src =" https://img.shields.io/github/actions/workflow/status/quantivio/PyNotion/formatting.yaml?style=for-the-badge " ></a >
12+ <a href =" https://black.readthedocs.io/en/stable/ " ><img alt =" Code Style " src =" https://img.shields.io/static/v1?label=CodeStyle&message=Black&color=%3CCOLOR%3E&style=for-the-badge " ></a >
13+ <a href =" https://www.python.org/ " ><img alt =" Static Badge " src =" https://img.shields.io/badge/Python-Lang?style=for-the-badge&label=Made%20With%20%E2%9D%A4%EF%B8%8F " ></a >
14+ </div >
15+
16+ <p style =" text-align : center ;" >
17+ PyNotion is a simple and intuitive Python library for accessing the Notion API. With PyNotion, you can easily integrate and automate Notion tasks within your Python projects.
18+ </p >
19+
20+ <p style =" text-align : center ;" >
21+ <strong >Please note that PyNotion is currently under development and may not yet be suitable for production use.</strong >
22+ </p >
1623
1724## Features
1825
@@ -21,29 +28,27 @@ PyNotion is currently in development and supports the following features:
21281 . Create new databases
22292 . Query existing databases
2330
24- [ ![ forthebadge made-with-python] ( http://ForTheBadge.com/images/badges/made-with-python.svg )] ( https://www.python.org/ )
25-
26- # Installing PyNotion
31+ ## Installation
2732
2833You can install PyNotion using either [ Poetry] ( https://python-poetry.org/ ) or [ pip] ( https://pypi.org/project/pip/ ) .
2934
30- ## Using Poetry
35+ ### Using Poetry
3136
3237To install PyNotion using Poetry, run the following command in your terminal:
3338
3439``` bash
3540poetry add pynotionclient
3641```
3742
38- ## Using pip
43+ ### Using pip
3944
4045To install PyNotion using pip, run the following command in your terminal:
4146
4247``` bash
4348pip install pynotionclient
4449```
4550
46- ## Usage
51+ ## Quick Start
4752
4853``` python
4954from pynotionclient import PyNotion
@@ -71,158 +76,149 @@ response_filter_payload: NotionDatabaseResponseSchema = py_notion_client.databas
7176
7277## Querying a Database
7378
74- #### 1. Querying a database using a dictionary
75-
76- ``` python
77- from pynotionclient import PyNotion
78- from examples.config import base_config
79- from pynotionclient.schema.database import NotionDatabaseResponseSchema
80-
81- py_notion_client = PyNotion(token = base_config.notion_secret_token)
82-
83- # Create necessary properties as dictionary
84- filter_dict = {" page_size" : 100 , " filter" : {" property" : " Name" , " rich_text" : {" contains" : " Home" }}}
85- response_dict_payload: NotionDatabaseResponseSchema = py_notion_client.database.query_database(
86- database_id = base_config.database_id, payload = filter_dict
87- )
88- ```
89-
90- #### 2. Querying a database using a Pydantic model
91-
92- ``` python
93- from pynotionclient import PyNotion
94- from examples.config import base_config
95- from pynotionclient.schema.database import RichTextFilter, PropertyFilter, Filter, NotionDatabaseResponseSchema
96-
97- py_notion_client = PyNotion(token = base_config.notion_secret_token)
79+ 1 . Querying a database using a dictionary
80+
81+ ``` python
82+ from pynotionclient import PyNotion
83+ from examples.config import base_config
84+ from pynotionclient.schema.database import NotionDatabaseResponseSchema
85+
86+ py_notion_client = PyNotion(token = base_config.notion_secret_token)
87+
88+ # Create necessary properties as dictionary
89+ filter_dict = {" page_size" : 100 , " filter" : {" property" : " Name" , " rich_text" : {" contains" : " Home" }}}
90+ response_dict_payload: NotionDatabaseResponseSchema = py_notion_client.database.query_database(
91+ database_id = base_config.database_id, payload = filter_dict
92+ )
93+ ```
94+
95+ 2 . Querying a database using a Pydantic model
96+ ```python
97+ from pynotionclient import PyNotion
98+ from examples.config import base_config
99+ from pynotionclient.schema.database import RichTextFilter, PropertyFilter, Filter, NotionDatabaseResponseSchema
100+
101+ py_notion_client = PyNotion(token = base_config.notion_secret_token)
102+
103+ # Create necessary filter objects from Pydantic models and use them to query the database.
104+
105+ rich_text_filter = RichTextFilter(contains = " Game" )
106+ property_filter = PropertyFilter(property = " Name" , rich_text = rich_text_filter)
107+ filter_object = Filter(page_size = 100 , filter = property_filter)
108+
109+ response_filter_payload: NotionDatabaseResponseSchema = py_notion_client.database.query_database(
110+ database_id = base_config.database_id, payload = filter_object)
111+ ```
112+
113+ # ### Response for querying a database
114+ > PyNotion client gives you the response as a Pydantic model. You can access the response as a dictionary or as a Pydantic model. The response is a NotionDatabaseResponseSchema model which has the following properties: https:// developers.notion.com/ reference/ database
115+
116+ 3 . Creating a Database
117+
118+ ```python
119+ from dotenv import load_dotenv
120+
121+ from examples.config import base_config
122+ from pynotionclient import PyNotion
123+ from pynotionclient.schema.database import (
124+ ParentConfiguration,
125+ IconConfiguration,
126+ TextConfiguration,
127+ ExternalConfiguration,
128+ CoverConfiguration,
129+ SelectOptionsConfiguration,
130+ SelectOptionsListConfig,
131+ TitleConfiguration,
132+ RichTextConfiguration,
133+ CheckboxConfiguration,
134+ SelectConfiguration,
135+ ContentConfiguration,
136+ MultiSelectConfiguration,
137+ NumberConfiguration,
138+ NumberFormats,
139+ NumberFormatConfiguration,
140+ DatabasePropertyConfiguration,
141+ )
142+
143+ load_dotenv()
144+ py_notion_client = PyNotion(token = base_config.notion_secret_token)
145+
146+ # # Create database payload
147+ parent_payload = ParentConfiguration(
148+ type = " page_id" , page_id = base_config.page_id
149+ ) # The parent is the page where the database will be created.
150+ icon_payload = IconConfiguration(
151+ type = " emoji" , emoji = " 🎮"
152+ ) # The icon is the icon that will be displayed on the database.
153+ text = TextConfiguration(
154+ content = " Game"
155+ ) # The text is the text that will be displayed as the title of the database.
156+ content = ContentConfiguration(
157+ type = " text" , plain_text = " Game" , href = " https://www.google.com" , text = text
158+ ) # The content has other info's of the title.
159+
160+ # Cover schema
161+ cover = CoverConfiguration(
162+ type = " external" , external = ExternalConfiguration(url = " https://www.google.com" )
163+ )
164+
165+ # # Forming select options schema
166+ properties = {
167+ " Name" : TitleConfiguration().model_dump(),
168+ " Description" : RichTextConfiguration().model_dump(),
169+ " In stock" : CheckboxConfiguration().model_dump(),
170+ " Food Group" : SelectConfiguration(
171+ select = SelectOptionsListConfig(
172+ options = [
173+ SelectOptionsConfiguration(color = " green" , name = " Code" ),
174+ SelectOptionsConfiguration(color = " red" , name = " Game" ),
175+ ],
176+ )
177+ ).model_dump(),
178+ " Cusines" : MultiSelectConfiguration(
179+ multi_select = SelectOptionsListConfig(
180+ options = [
181+ SelectOptionsConfiguration(color = " green" , name = " Code" ),
182+ SelectOptionsConfiguration(color = " red" , name = " Game" ),
183+ ],
184+ )
185+ ).model_dump(),
186+ " Price" : NumberConfiguration(
187+ number = NumberFormatConfiguration(
188+ format = NumberFormats.NUMBER_WITH_COMMAS ,
189+ ),
190+ ).model_dump(),
191+ }
192+ print (properties)
193+ create_database_payload = DatabasePropertyConfiguration(
194+ title = [content],
195+ cover = cover,
196+ parent = parent_payload,
197+ icon = icon_payload,
198+ properties = properties,
199+ )
200+
201+ response = py_notion_client.database.create_database(
202+ payload = create_database_payload,
203+ )
204+
205+ print (response.json())
206+ ```
98207
99- # Create necessary filter objects from Pydantic models and use them to query the database.
100-
101- rich_text_filter = RichTextFilter(contains = " Game" )
102- property_filter = PropertyFilter(property = " Name" , rich_text = rich_text_filter)
103- filter_object = Filter(page_size = 100 , filter = property_filter)
104-
105- response_filter_payload: NotionDatabaseResponseSchema = py_notion_client.database.query_database(
106- database_id = base_config.database_id, payload = filter_object)
107- ```
108-
109- #### Response for querying a database
110-
111- > Pynotion client gives you the response as a Pydantic model. You can access the response as a dictionary or as a
112- > Pydantic model. The response is a NotionDatabaseResponseSchema model which has the following
113- > properties: https://developers.notion.com/reference/database
114-
115- #### 3. Creating a database
116-
117- ``` python
118- from dotenv import load_dotenv
119-
120- from examples.config import base_config
121- from pynotionclient import PyNotion
122- from pynotionclient.schema.database import (
123- ParentConfiguration,
124- IconConfiguration,
125- TextConfiguration,
126- ExternalConfiguration,
127- CoverConfiguration,
128- SelectOptionsConfiguration,
129- SelectOptionsListConfig,
130- TitleConfiguration,
131- RichTextConfiguration,
132- CheckboxConfiguration,
133- SelectConfiguration,
134- ContentConfiguration,
135- MultiSelectConfiguration,
136- NumberConfiguration,
137- NumberFormats,
138- NumberFormatConfiguration,
139- DatabasePropertyConfiguration,
140- )
141-
142- load_dotenv()
143- py_notion_client = PyNotion(token = base_config.notion_secret_token)
144-
145- # # Create database payload
146- parent_payload = ParentConfiguration(
147- type = " page_id" , page_id = base_config.page_id
148- ) # The parent is the page where the database will be created.
149- icon_payload = IconConfiguration(
150- type = " emoji" , emoji = " 🎮"
151- ) # The icon is the icon that will be displayed on the database.
152- text = TextConfiguration(
153- content = " Game"
154- ) # The text is the text that will be displayed as the title of the database.
155- content = ContentConfiguration(
156- type = " text" , plain_text = " Game" , href = " https://www.google.com" , text = text
157- ) # The content has other info's of the title.
158-
159- # Cover schema
160- cover = CoverConfiguration(
161- type = " external" , external = ExternalConfiguration(url = " https://www.google.com" )
162- )
163-
164- # # Forming select options schema
165- properties = {
166- " Name" : TitleConfiguration().dict(),
167- " Description" : RichTextConfiguration().dict(),
168- " In stock" : CheckboxConfiguration().dict(),
169- " Food Group" : SelectConfiguration(
170- select = SelectOptionsListConfig(
171- options = [
172- SelectOptionsConfiguration(color = " green" , name = " Code" ),
173- SelectOptionsConfiguration(color = " red" , name = " Game" ),
174- ],
175- )
176- ).dict(),
177- " Cusines" : MultiSelectConfiguration(
178- multi_select = SelectOptionsListConfig(
179- options = [
180- SelectOptionsConfiguration(color = " green" , name = " Code" ),
181- SelectOptionsConfiguration(color = " red" , name = " Game" ),
182- ],
183- )
184- ).dict(),
185- " Price" : NumberConfiguration(
186- number = NumberFormatConfiguration(
187- format = NumberFormats.NUMBER_WITH_COMMAS ,
188- ),
189- ).dict(),
190- }
191- print (properties)
192- create_database_payload = DatabasePropertyConfiguration(
193- title = [content],
194- cover = cover,
195- parent = parent_payload,
196- icon = icon_payload,
197- properties = properties,
198- )
199-
200- response = py_notion_client.database.create_database(
201- payload = create_database_payload,
202- )
203-
204- print (response.json())
205- ```
206208
207209# PyNotion Development Setup
208-
209210Follow these steps to set up your development environment for PyNotion:
210211
211212# # Virtual Environment with Poetry
212-
2132131 . Create a fork of the PyNotion repository
2142142 . Clone the repository to your local machine: `git clone git@ github.com:< username> / PyNotion.git`
215- 3 . Install Poetry: ` pip install poetry ` or ` pip3 install poetry `
215+ 3 . Install Poetry: `pip install poetry or pip3 install poetry`
2162164 . Navigate to the root of the project and run: `poetry install`
217217
218218# # Pre-commit Hooks
219-
2202191 . Install pre- commit hooks: `pre- commit install`
2212202 . Migrate pre- commit configurations: `pre- commit migrate- config`
222- 3 . If you encounter an error, run: ` git config --global --unset-all core.hooksPath `
223- or ` git config --unset-all core.hooksPath `
221+ 3 . If you encounter an error, run: `git config -- global -- unset- all core.hooksPath or git config -- unset- all core.hooksPath`
224222
225223# # Contributing
226-
227- We welcome contributions to PyNotion! Before making a major change, please open an issue to discuss your proposed
228- changes. To submit a contribution, simply create a pull request.
224+ We welcome contributions to PyNotion! Before making a major change, please open an issue to discuss your proposed changes. To submit a contribution, simply create a pull request.
0 commit comments