API wrapper for Notion written in Python
Project description
notion-python
notion-python is an API wrapper for Notion, written in Python.
This library uses Oauth2 for authentication.
Installing
pip install notion-python-2
Usage
- If you don't have an access token:
from notion.client import Client
client = Client(client_id, client_secret, redirect_uri)
To obtain and set an access token, follow this instructions:
- Get authorization URL
url = client.authorization_url()
- Get access token using code
response = client.get_access_token(code)
- Set access token
client.set_token(access_token)
Check more information about Notion Oauth: https://developers.notion.com/docs/authorization
- If you already have an access token:
from notion.client import Client
client = Client(access_token=access_token)
User
- Get Current User
user = client.get_current_user()
- List users
users = client.list_users(page_size=3)
# page_size: max 100
# start_cursor: pagination variable, get this value from previous page 'next_cursor' parameter.
Databases and Pages
- List all objects
# object_type options are: page or database
# page_size: max 100
# start_cursor: pagination variable, get this value from previous page 'next_cursor' parameter.
databases_list = client.list_objects("database", page_size=5)
- Get database
database = client.get_database(database_id)
- Query database pages
How to build a filter object: https://developers.notion.com/reference/post-database-query-filter
How to build a sort object: https://developers.notion.com/reference/post-database-query-sort
filter_criteria = {"property": "Main Email", "email": {"equals": "example@mail.com"}}
# Where 'Main Email' is the field name and 'email' is the field type
pages = client.query_database_pages(
database_id,
filters=filter_criteria,
sorts: dict = None,
start_cursor=None,
page_size=None
)
- Create page
properties_example = {
"Project name": {
"title": [
{
"text": {
"content": "First project built with this library"
}
}
]
},
}
cover_url = "https://upload.wikimedia.org/wikipedia/commons/1/1/example.jpg"
page = client.create_page(database_id, properties_example, cover_url=cover_url)
- Update page
properties_example = {
"Project name": {
"title": [
{
"text": {
"content": "Project field modified"
}
}
]
},
}
page = client.update_page(page_id, properties_example, cover_url=None)
How to build a properties object: https://developers.notion.com/reference/page-property-values
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file notion_python_2-0.1.1.tar.gz
.
File metadata
- Download URL: notion_python_2-0.1.1.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33d1bd68c74a7ab37900ccbc6265ccce23b57da77822ec55c432c95e99bc0cfe |
|
MD5 | 98e311e0f4114ed24edb41da68d76918 |
|
BLAKE2b-256 | 81de3964cbf44d3d967d767d8da988eb590193e521d9a8f5969605c393546528 |
File details
Details for the file notion_python_2-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: notion_python_2-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7154fa1677987ab218cc4e3fa66a1bd1a539b48f872211aa818cb6332ef70e8e |
|
MD5 | 08bbf1fd023374fa4119b4a844906e49 |
|
BLAKE2b-256 | 4622f2a52b4e34ae2b3cad2e954d49238b58023163aeba002f54ae55d663cd01 |