|
1 | 1 | # PyNotion |
2 | 2 |
|
3 | | -A Notion API wrapper for Python |
| 3 | +<img src="assets/notion.png" alt="Notion Logo" height="64" width="64"> |
| 4 | +<br> |
| 5 | + |
| 6 | +### A Notion API wrapper for Python (In Development) |
| 7 | + |
| 8 | +> Simple to use and easy to understand API wrapper for Notion.so |
| 9 | +> |
| 10 | +>Curently in development and supports the following features: |
| 11 | +> 1. Create a new database (Work in progress can create datbase passing payload as a dictionary) |
| 12 | +> 2. Get a database |
| 13 | +
|
| 14 | +## Installation |
| 15 | + |
| 16 | +`poetry add pynotionclient` |
| 17 | + |
| 18 | +`pip install pynotionclient` |
| 19 | + |
| 20 | +## Usage |
| 21 | + |
| 22 | +```python |
| 23 | +py_notion_client = PyNotion(token=base_config.notion_secret_token) |
| 24 | + |
| 25 | +# Create necessary properties as dictionary |
| 26 | +filter_dict = {"page_size": 100, "filter": {"property": "Name", "rich_text": {"contains": "Home"}}} |
| 27 | + |
| 28 | +# Create necessary filter objects from Pydantic models and use them to query the database. |
| 29 | + |
| 30 | +rich_text_filter = RichTextFilter(contains="Game") |
| 31 | +property_filter = PropertyFilter(property="Name", rich_text=rich_text_filter) |
| 32 | +filter_object = Filter(page_size=100, filter=property_filter) |
| 33 | + |
| 34 | +response_dict_payload: NotionDatabaseResponseSchema = py_notion_client.database.query_database( |
| 35 | + database_id=base_config.database_id, payload=filter_dict |
| 36 | + ) |
| 37 | +response_filter_payload: NotionDatabaseResponseSchema = py_notion_client.database.query_database( |
| 38 | + database_id=base_config.database_id, payload=filter_object |
| 39 | + ) |
| 40 | +``` |
| 41 | + |
| 42 | +## Querying a Database |
| 43 | + |
| 44 | +#### 1. Querying a database using a dictionary |
| 45 | + |
| 46 | +```python |
| 47 | +py_notion_client = PyNotion(token=base_config.notion_secret_token) |
| 48 | + |
| 49 | +# Create necessary properties as dictionary |
| 50 | +filter_dict = {"page_size": 100, "filter": {"property": "Name", "rich_text": {"contains": "Home"}}} |
| 51 | +response_dict_payload: NotionDatabaseResponseSchema = py_notion_client.database.query_database( |
| 52 | + database_id=base_config.database_id, payload=filter_dict |
| 53 | + ) |
| 54 | +``` |
| 55 | + |
| 56 | +#### 2. Querying a database using a Pydantic model |
| 57 | + |
| 58 | +```python |
| 59 | +py_notion_client = PyNotion(token=base_config.notion_secret_token) |
| 60 | + |
| 61 | +# Create necessary filter objects from Pydantic models and use them to query the database. |
| 62 | + |
| 63 | +rich_text_filter = RichTextFilter(contains="Game") |
| 64 | +property_filter = PropertyFilter(property="Name", rich_text=rich_text_filter) |
| 65 | +filter_object = Filter(page_size=100, filter=property_filter) |
| 66 | + |
| 67 | +response_filter_payload: NotionDatabaseResponseSchema = py_notion_client.database.query_database( |
| 68 | + database_id=base_config.database_id, payload=filter_object |
| 69 | +``` |
| 70 | + |
| 71 | +#### Response for querying a database |
| 72 | + |
| 73 | +> Pynotionclient gives you the response as a Pydantic model. You can access the response as a dictionary or as a |
| 74 | +> Pydantic model. The response is a NotionDatabaseResponseSchema model which has the following |
| 75 | +> properties: https://developers.notion.com/reference/database |
| 76 | + |
| 77 | +## Contributing |
| 78 | + |
| 79 | +Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. |
0 commit comments