Skip to main content

An object model for the Notion SDK.

Project description

notional

A simplified object model for the Notion SDK.

:warning: Work In Progress: The interfaces in this module are still in development and are likely to change frequently. Furthermore, documentation is pretty sparse so use at your own risk!

That being said, if you do use this library, please drop a message! I'd love to see your use case and how you are incorporating this into your project.

Installation

Install using PyPi:

pip install notional

Note: it is recommended to use a virtual environment (venv) for installing libraries to prevent conflicting dependency versions.

Usage

Connect to the API using an integration token or an OAuth access token:

import notional

notion = notional.connect(auth=AUTH_TOKEN)

# do some things

notion.commit()

Iterators

The iterators provide convenient access to the Notion endpoints. Rather than looking for each page of data, the iterators take care of this and expose a standard Python iterator:

import notional

from notional.iterator import EndpointIterator

notion = notional.connect(auth=AUTH_TOKEN)

tasks = EndpointIterator(
    endpoint=notion.databases.query,
    database_id=task_db_id,
    sorts=[
        {
            'direction': 'ascending',
            'property': 'Last Update'
        }
    ]
)

for data in tasks:
    # do the things

Note that the parameters to the iterator follow the standard API parameters for the given endpoint.

ORM

This library has support for defining custom data types that wrap Notion pages. Typically, these pages are entries in a database (collection) with a consistent schema.

Currently, there is not a good way to iterate over custom data types. This will be fixed in a future release.

from notional import types
from notional.records import Page, Property

class Task(Page):
    Title = Property('Title', types.Title)
    Priority = Property('Priority', types.SelectOne)
    DueDate = Property('Due Date', types.Date)

for data in tasks:
    task = Task(**data)
    print(f"{task.Title} => {task.Priority}")
    task.DueDate = date.today()
    task.commit()

See the examples for more information.

Token Security

It is generally a best practice to read the auth token from an environment variable or a secrets file. To prevent accidental exposure, it is NOT recommended to save the token in source. For more information, read about Notion authorization here.

Contributing

I built this module so that I could interact with Notion in a way that made sense to me. Hopefully, others will find it useful. If someone is particularly passionate about this area, I would be happy to consider other maintainers or contributors.

Any pull requests or other submissions are welcome. As most open source projects go, this is a side project. Large submissions will take time to review for acceptance, so breaking them into smaller pieces is always preferred. Thanks in advance!

Formatted using black.

Known Issues

See Issues on github.

Feature Requests

See Issues on github.

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

notional-0.0.2.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

notional-0.0.2-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

Details for the file notional-0.0.2.tar.gz.

File metadata

  • Download URL: notional-0.0.2.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6

File hashes

Hashes for notional-0.0.2.tar.gz
Algorithm Hash digest
SHA256 5af45e2c8d9eb50722e137bb5dd9c5c6c9f9718962b07df358983b313bc973e4
MD5 89df0308191266aed250b6e63064c356
BLAKE2b-256 92beeee21c835eae283fbff39e23c07eeda7dba02dcc8d7d8d97fd05524f95b0

See more details on using hashes here.

File details

Details for the file notional-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: notional-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 10.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6

File hashes

Hashes for notional-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 61d7bf662f5add40044c99d6a3f5f009486d7dd2b43785bbebac361a413b7322
MD5 559301569cab39035e647613962a0a81
BLAKE2b-256 abfc19fe2345380f6bdde96e4515da78aa293d9f68713b6f1ee5b277101773cf

See more details on using hashes here.

Supported by

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