Skip to main content

Client-agnostic model wrapper for Notion API

Project description

basic-notion

Client-agnostic model wrapper for Notion API

##Installation

Just like any othjer python package out there, it can be installed via pip

pip install basic-notion

Basic Examples

Describing Models

from basic_notion.base import NotionPage, NotionList
from basic_notion.field import SelectField, TitleField 


class ReadingListItem(NotionPage):
    type: SelectField = SelectField(property_name='Type')
    name: TitleField = TitleField(property_name='Name')


class ReadingList(NotionList[ReadingListItem]):
    _ITEM_CLS = ReadingListItem

Using With notion-sdk-py

import asyncio
import os

from notion_client import AsyncClient
from basic_notion.query import Query

from models import ReadingList


async def get_reading_list() -> ReadingList:
    database_id = os.environ.get('DATABASE_ID')
    notion_token = os.environ.get('NOTION_TOKEN')
    notion = AsyncClient(auth=notion_token)
    data = await notion.databases.query(
        **Query(database_id).filter(
            ReadingList.item.type.filter.equals('Book')
        ).serialize()
    )
    return ReadingList(data=data)


def print_reading_list(reading_list: ReadingList) -> None:
    for item in reading_list.items:
        print(f'[{item.type.name}] {item.name.one_item.content}')


async def main() -> None:
    reading_list = await get_reading_list()
    print_reading_list(reading_list)


asyncio.run(main())

(assuming you put the previous code in models.py)

See notion-sdk-py's homepage for more info on the client: https://github.com/ramnes/notion-sdk-py

Links

Homepage on GitHub: https://github.com/altvod/basic-notion

Project's page on PyPi: https://pypi.org/project/basic-notion/

Notion API: https://developers.notion.com/

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

basic-notion-0.0.2.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

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

basic_notion-0.0.2-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file basic-notion-0.0.2.tar.gz.

File metadata

  • Download URL: basic-notion-0.0.2.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for basic-notion-0.0.2.tar.gz
Algorithm Hash digest
SHA256 e235e1b76c35cb3b0f2c435fb4d9d7f7bd06081255e48702faeaa1b169ba1b32
MD5 088648119dec625bf077d07150e5ce77
BLAKE2b-256 d3519b0394a02885a6faa8e2d8581926c65051e6cc21daf308e16fcbccf27292

See more details on using hashes here.

File details

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

File metadata

  • Download URL: basic_notion-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for basic_notion-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4fbec21ad41c7b9d9b96a8575e8b52b4915704875435b9ae2df8696bf3bfa23a
MD5 8bd2f7a9e7c317157f4ef62d1bc48889
BLAKE2b-256 688217846fb16afca677f722956ef7665a6080c866560766aa820ae6af28934f

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