Notion API Database Python Implementation
Reason this release was yanked:
Stable version 1.0.0 has been released. Install that version only if migration is not possible.
Project description
Python Notion Database
Notion API Database Python Implementation
created only by database from the official Notion API.
What's new
-
2021.10.24
- Children Blocks are now supported!
-
2021.07.13
-
2021.07.15
- Create new databases
-
2021.09.01
- Update notion-version (2021-08-16)
- Get/Remove Properties & Update Database
Installing / Getting started
pip install notion-database
List Database
from notion_database.database import Database
D = Database(integrations_token=NOTION_KEY)
D.list_databases(page_size=100)
Retrieve Database
from notion_database.database import Database
D = Database(integrations_token=NOTION_KEY)
D.retrieve_database(database_id=database_id)
Properties
- For Database
from notion_database.properties import Properties
PROPERTY = Properties()
PROPERTY.set_title("name")
PROPERTY.set_rich_text("description")
PROPERTY.set_number("number")
PROPERTY.set_select("select")
PROPERTY.set_multi_select("multi_select")
PROPERTY.set_checkbox("checkbox")
PROPERTY.set_url("url")
PROPERTY.set_email("email")
PROPERTY.set_phone_number("phone")
- For Page
from notion_database.properties import Properties
PROPERTY = Properties()
PROPERTY.set_title("name", "title")
PROPERTY.set_rich_text("description", "notion-database")
PROPERTY.set_number("number", 1)
PROPERTY.set_select("select", "test1")
PROPERTY.set_multi_select("multi_select", ["test1", "test2"])
PROPERTY.set_checkbox("checkbox", True)
PROPERTY.set_url("url", "www.google.com")
PROPERTY.set_email("email", "test@test.com")
PROPERTY.set_phone_number("phone", "010-0000-0000")
Create Page
from notion_database.page import Page
P = Page(integrations_token=NOTION_KEY)
P.create_page(database_id=database_id, properties=PROPERTY, children=children)
page_id = P.result["id"]
Retrieve Page
from notion_database.page import Page
P = Page(integrations_token=NOTION_KEY)
P.retrieve_page(page_id=page_id)
Update Page
from notion_database.page import Page
P = Page(integrations_token=NOTION_KEY)
P.update_page(page_id=page_id, properties=PROPERTY)
Clear Properties
from notion_database.properties import Properties
PROPERTY = Properties()
PROPERTY.clear()
Archive Page
from notion_database.page import Page
P = Page(integrations_token=NOTION_KEY)
P.archive_page(page_id=page_id, archived=True)
Create database
from notion_database.database import Database
D = Database(integrations_token=NOTION_KEY)
D.create_database(page_id=page_id, title="TEST TITLE", properties=PROPERTY)
Finding all pages in a database
from notion_database.database import Database
import pprint
D = Database(integrations_token=NOTION_KEY)
D.find_all_page(database_id=database_id)
pprint.pprint(D.result)
Get Properties
from notion_database.database import Database
D = Database(integrations_token=NOTION_KEY)
D.retrieve_database(database_id, get_properties=True)
properties_list = D.properties_list
Remove Properties / Update Database
from notion_database.database import Database
D = Database(integrations_token=NOTION_KEY)
D.update_database(database_id=database_id, title="DB", add_properties=PROPERTY)
or
from notion_database.database import Database
D = Database(integrations_token=NOTION_KEY)
D.update_database(database_id=database_id, title="DB", remove_properties=D.properties_list)
or
from notion_database.database import Database
D = Database(integrations_token=NOTION_KEY)
D.update_database(database_id=database_id, title="DB", remove_properties=D.properties_list, add_properties=PROPERTY)
Children block
from notion_database.children import Children
children = Children()
children.set_paragraph("set_paragraph")
children.set_heading_1("set_heading_1")
children.set_heading_2("set_heading_2")
children.set_heading_3("set_heading_3")
children.set_callout("set_callout")
children.set_quote("set_quote")
children.set_bulleted_list_item("set_bulleted_list_item")
children.set_numbered_list_item("first set_numbered_list_item")
children.set_to_do("set_to_do", checked=True)
children.set_toggle("set_toggle", children_text="WOW!")
children.set_code("print(\"hello world!\")", lang='python')
children.set_embed("https://www.google.com")
children.set_external_image("https://github.githubassets.com/images/modules/logos_page/Octocat.png")
children.set_external_video("http://download.blender.org/peach/trailer/trailer_480p.mov")
children.set_external_file("https://github.com/microsoft/ML-For-Beginners/raw/main/pdf/readme.pdf")
children.set_external_pdf("https://github.com/microsoft/ML-For-Beginners/blob/main/pdf/readme.pdf")
children.set_bookmark("https://www.google.com")
children.set_equation("e=mc^2")
children.set_divider()
children.set_table_of_contents()
children.set_breadcrumb()
# P.create_page(database_id=database_id, properties=PROPERTY, children=children)
Building / Developing
python setup.py install
Features
-
list database
-
Retrieve database
-
Create database
-
Create Page object (the database item)
-
update Page object
-
Retrieve Page object
-
Archive Page
-
Finding all pages in a database
-
Get Properties
-
Remove Properties
-
Update Database
-
Add Children Block with page
Todo
- query database (wip) # help me!
Contributing
If you'd like to contribute, please fork the repository and use a feature branch. Pull requests are warmly welcome.
Links
- Notion API : https://developers.notion.com
Licensing
The code in this project is licensed under GPL license.
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
Hashes for notion-database-20210816.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 54cbbd6871fa53f5f710d6632e4e56e44062b07f2349c55e9237ee1b12da2dc0 |
|
MD5 | c64d1d6d45cf206bf216943f39c9e03b |
|
BLAKE2b-256 | 4b7b3be561cbc8583f6d95c5988531de82f20f6a859aa935824bc52f5f585f09 |
Hashes for notion_database-20210816.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a318e45de4b50bf4b0799e5cac9be098d7c9c58c4c3112e32fd0aba589739c28 |
|
MD5 | cdd663fdc4916e9f7ba7fd931e785bfc |
|
BLAKE2b-256 | 567da6e056641283ebcc7421a9533a4def354ccff4dae7095aa9cdda878da2d6 |