Skip to main content

A python library to work with objects retrieved from the notion API

Project description

notion-objects

Build Status PyPI Version PyPI License Codestyle

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


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)

Uploaded Source

Built Distribution

notion_objects-0.1.0-py3-none-any.whl (9.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page