A python library to work with objects retrieved from the notion API
Project description
notion-objects
A Python library that makes it easy to work with notion databases.
Usage
Suppose your database tasks
has four fields, the title Task
, a date range Date
, and a person Assigned to
, and a status field Status
.
You want to transform notion database queries into records of:
{"task": "my task", "date_start": "2022-01-01", "date_end": "2022-01-02", "assigned_to": "Thomas", "status": "In progress"}
First, declare a model that contains all the necessary transformations as descriptors:
from notion_objects import *
class Task(NotionObject):
task = TitleText("Task")
assigned_to = Person("Assigned to")
date_start = DateRangeStart("Date")
date_end = DateRangeEnd("Date")
status = Status("Status")
Now, when you have queried a database, you can instantiate Task
objects with the results of the API call:
response = requests.post("https://api.notion.com/v1/databases/{database_id}/query", ...)
for item in response.json()['results']:
t = Task(item)
print(t.task) # access attribute values
print(t.to_json()) # prints the record in the json format show earlier
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
notion-objects-0.1.0.tar.gz
(8.9 kB
view hashes)
Built Distribution
Close
Hashes for notion_objects-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 10bacb5f71a0aa67f9b540a8913590ba8cf41a0bdbd2dd58d66658e405aadc36 |
|
MD5 | 452d777e9a0c5e00bef661f8bb8fce0e |
|
BLAKE2b-256 | 5a58cbe0f89f5fc9e01dc3203d82132ed6115cd8513211dbe86d5c45a8fa888d |