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
Built Distribution
Close
Hashes for notion-objects-0.1.0.post1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b46fef01d8362504ec05165d94f6c673a5800a976138741751e4d30749efb2d |
|
MD5 | b185ed084b03768cb26fd43038516881 |
|
BLAKE2b-256 | 9f194f269d19dfb930a131fcad300662f20d1227fbc7655a8847479c8edbef66 |
Close
Hashes for notion_objects-0.1.0.post1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ade077c4d4ef3bb4223b81c3823d040ceb7118a90abce9be94894b2101567819 |
|
MD5 | 79e0cb9958fefc58dbf1034c8bec4ead |
|
BLAKE2b-256 | 64ba5f08e547c67a165c6fe672b1125a8d5d30de7e0fbdb5ded557f35ac965a1 |