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
Metadata
Release files for notion-python-2 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| notion_python_2-0.1.2.tar.gz | 4.3 kB | Without provenance | Details for notion_python_2-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| notion_python_2-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for notion_python_2-0.1.2-py3-none-any.whl |
Total release size: 9.3 kB
Release files / notion_python_2-0.1.2.tar.gz
| Download URL | notion_python_2-0.1.2.tar.gz |
|---|---|
| Size | 4.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0e8c0722b4562353aae9d6eed7e9283387370b81363a26f307cffd4e294ad22d
|
|
BLAKE2b-256 checksum How to use checksums |
eb89e060197e3cdb932eb01cf1ca9fec72aba148667784f47051a65512a67ddb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.8.10
|
Release files / notion_python_2-0.1.2-py3-none-any.whl
| Download URL | notion_python_2-0.1.2-py3-none-any.whl |
|---|---|
| Size | 5.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f842bced668876480a5d155936eea16df1393af2d3185b809ff3af0bc73d454e
|
|
BLAKE2b-256 checksum How to use checksums |
136732fb85d0c9639f53c70b2d8933e41cc01d54f8012bc889c5437cb1867f90
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.8.10
|
Security for notion-python-2 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.