Skip to content

Commit a375160

Browse files
author
Vetrichelvan
committed
Added configuration schemas for making request, removed deprecated type hint
1 parent 5a135c5 commit a375160

50 files changed

Lines changed: 768 additions & 341 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.pylintrc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ ignore-patterns=^\.#
6161
# supports qualified module names, as well as Unix pattern matching.
6262
ignored-modules=
6363

64-
disable = C0115, C0116, C0114, R1705, R0801, E1101
64+
disable = C0115, C0116, C0114, R1705, R0801, E1101, R6003, E0213, W0511
6565

6666
# Python code to execute, usually for sys.path manipulation such as
6767
# pygtk.require().
@@ -621,4 +621,3 @@ variable-naming-style=snake_case
621621

622622

623623
string-quote=double
624-
triple-quote=triple

README.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,17 @@
1212

1313
### A Notion API wrapper for Python (In Development)
1414

15-
> Simple to use and easy to understand API wrapper for Notion.so
16-
>
17-
>Curently in development and supports the following features:
18-
> 1. Create a new database (Work in progress can create datbase passing payload as a dictionary)
19-
> 2. Get a database
15+
Simple to use and easy to understand API wrapper for Notion.so Curently in development and
16+
supports the following features:
17+
1. Create a new database (Work in progress can create datbase passing payload as a dictionary)
18+
2. Get a database
2019

2120
## Installation
22-
2321
`poetry add pynotionclient`
2422

2523
`pip install pynotionclient`
2624

2725
## Usage
28-
2926
```python
3027
from pynotionclient import PyNotion
3128
from examples.config import base_config

examples/__init__.py

Whitespace-only changes.

examples/database.py

Lines changed: 0 additions & 82 deletions
This file was deleted.

examples/database/__init__.py

Whitespace-only changes.
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
from dotenv import load_dotenv
2+
3+
from examples.config import base_config
4+
from pynotionclient import PyNotion
5+
from pynotionclient.schema.database import (
6+
ParentConfiguration,
7+
IconConfiguration,
8+
TextConfiguration,
9+
ExternalConfiguration,
10+
CoverConfiguration,
11+
SelectOptionsConfiguration,
12+
SelecOptionsListConfig,
13+
TitleConfiguration,
14+
RichTextConfiguration,
15+
CheckboxConfiguration,
16+
SelectConfiguration,
17+
ContentConfiguration,
18+
MultiSelectConfiguration,
19+
NumberConfiguration,
20+
NumberFormats,
21+
NumberFormatConfiguration,
22+
DatabasePropertyConfiguration,
23+
)
24+
25+
load_dotenv()
26+
py_notion_client = PyNotion(token=base_config.notion_secret_token)
27+
28+
# # Create database payload
29+
parent_payload = ParentConfiguration(
30+
type="page_id", page_id=base_config.page_id
31+
) # The parent is the page where the database will be created.
32+
icon_payload = IconConfiguration(
33+
type="emoji", emoji="🎮"
34+
) # The icon is the icon that will be displayed on the database.
35+
text = TextConfiguration(
36+
content="Game"
37+
) # The text is the text that will be displayed as the title of the database.
38+
content = ContentConfiguration(
39+
type="text", plain_text="Game", href="https://www.google.com", text=text
40+
) # The content has other info's of the title.
41+
42+
# Cover schema
43+
cover = CoverConfiguration(
44+
type="external", external=ExternalConfiguration(url="https://www.google.com")
45+
)
46+
47+
# # Forming select options schema
48+
properties = {
49+
"Name": TitleConfiguration().dict(),
50+
"Description": RichTextConfiguration().dict(),
51+
"In stock": CheckboxConfiguration().dict(),
52+
"Food Group": SelectConfiguration(
53+
select=SelecOptionsListConfig(
54+
options=[
55+
SelectOptionsConfiguration(color="green", name="Code"),
56+
SelectOptionsConfiguration(color="red", name="Game"),
57+
],
58+
)
59+
).dict(),
60+
"Cusines": MultiSelectConfiguration(
61+
multi_select=SelecOptionsListConfig(
62+
options=[
63+
SelectOptionsConfiguration(color="green", name="Code"),
64+
SelectOptionsConfiguration(color="red", name="Game"),
65+
],
66+
)
67+
).dict(),
68+
"Price": NumberConfiguration(
69+
number=NumberFormatConfiguration(
70+
format=NumberFormats.NUMBER_WITH_COMMAS,
71+
),
72+
).dict(),
73+
}
74+
print(properties)
75+
create_database_payload = DatabasePropertyConfiguration(
76+
title=[content],
77+
cover=cover,
78+
parent=parent_payload,
79+
icon=icon_payload,
80+
properties=properties,
81+
)
82+
83+
response = py_notion_client.database.create_database(
84+
payload=create_database_payload,
85+
)
86+
87+
print(response.json())
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
from dotenv import load_dotenv
2+
3+
from examples.config import base_config
4+
from pynotionclient import PyNotion
5+
from pynotionclient.schema.database import (
6+
RichTextFilter,
7+
PropertyFilter,
8+
Filter,
9+
ParentConfiguration,
10+
IconConfiguration,
11+
TextConfiguration,
12+
ExternalConfiguration,
13+
CoverConfiguration,
14+
SelectOptionsConfiguration,
15+
SelecOptionsListConfig,
16+
TitleConfiguration,
17+
RichTextConfiguration,
18+
CheckboxConfiguration,
19+
SelectConfiguration,
20+
ContentConfiguration,
21+
MultiSelectConfiguration,
22+
NumberConfiguration,
23+
NumberFormats,
24+
NumberFormatConfiguration,
25+
)
26+
27+
load_dotenv()
28+
py_notion_client = PyNotion(token=base_config.notion_secret_token)
29+
30+
filter_dict = {
31+
"page_size": 100,
32+
"filter": {"property": "Name", "rich_text": {"contains": "Home"}},
33+
}
34+
35+
# Create necessary filter objects from Pydantic models and use them to query the database.
36+
37+
rich_text_filter = RichTextFilter(contains="Game")
38+
property_filter = PropertyFilter(property="Name", rich_text=rich_text_filter)
39+
filter_object = Filter(page_size=100, filter=property_filter)
40+
41+
# response_dict_payload: NotionDatabaseResponseSchema = py_notion_client.database.query_database(
42+
# database_id=base_config.database_id, payload=filter_dict
43+
# )
44+
# response_filter_payload: NotionDatabaseResponseSchema = py_notion_client.database.query_database(
45+
# database_id=base_config.database_id, payload=filter_object
46+
# )
47+
48+
# # Since we are using pydantic the result can be used either as on object or as a dictionary or json.
49+
# # This gives the user the flexibility to use the result as they wish.
50+
# # Inside the properties use the key name you gave for each table in your database to access the value.
51+
# # For example: CustomizedSelect is the key name for the table named "CustomizedSelect" in my database.
52+
53+
# print(response_dict_payload.results[0].properties.Name.json(indent=4)) # Print the first result's Select property as json.
54+
# print(response_filter_payload.results[0].properties.Name.json(indent=4)) # Print the first result's Select property as json.
55+
56+
# # Create database payload
57+
parent_payload = ParentConfiguration(
58+
type="page_id", page_id=base_config.page_id
59+
) # The parent is the page where the database will be created.
60+
icon_payload = IconConfiguration(
61+
type="emoji", emoji="🎮"
62+
) # The icon is the icon that will be displayed on the database.
63+
text = TextConfiguration(
64+
content="Game"
65+
) # The text is the text that will be displayed as the title of the database.
66+
content = ContentConfiguration(
67+
type="text", plain_text="Game", href="https://www.google.com", text=text
68+
) # The content has other info's of the title.
69+
70+
# Cover schema
71+
cover = CoverConfiguration(
72+
type="external", external=ExternalConfiguration(url="https://www.google.com")
73+
)
74+
75+
# # Forming select options schema
76+
properties = {
77+
"Name": TitleConfiguration().dict(),
78+
"Description": RichTextConfiguration().dict(),
79+
"In stock": CheckboxConfiguration().dict(),
80+
"Food Group": SelectConfiguration(
81+
select=SelecOptionsListConfig(
82+
options=[
83+
SelectOptionsConfiguration(color="green", name="Code"),
84+
SelectOptionsConfiguration(color="red", name="Game"),
85+
],
86+
)
87+
).dict(),
88+
"Cusines": MultiSelectConfiguration(
89+
multi_select=SelecOptionsListConfig(
90+
options=[
91+
SelectOptionsConfiguration(color="green", name="Code"),
92+
SelectOptionsConfiguration(color="red", name="Game"),
93+
],
94+
)
95+
).dict(),
96+
"Price": NumberConfiguration(
97+
number=NumberFormatConfiguration(
98+
format=NumberFormats.NUMBER_WITH_COMMAS,
99+
),
100+
).dict(),
101+
}
102+
print(properties)
103+
# create_database_payload = DatabasePropertyConfiguration(
104+
# title=[content],
105+
# cover=cover,
106+
# parent=parent_payload,
107+
# icon=icon_payload,
108+
# properties=properties,
109+
# )
110+
#
111+
# response = py_notion_client.database.create_database(
112+
# payload=create_database_payload,
113+
# )
114+
#
115+
# print(response.json())

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
url="https://github.com/pythonhubpy/PyNotion",
2828
packages=find_packages(exclude=["tests"]),
2929
install_package_data=True,
30-
install_requires=["requests", "pydantic"],
30+
install_requires=["request", "pydantic"],
3131
classifiers=classifiers,
3232
python_requires=">=3.8",
3333
)

0 commit comments

Comments
 (0)