Skip to main content

Airflow provider for Notion API integration

Project description

Airflow Notion Provider

This provider enables Apache Airflow to integrate with Notion API, allowing you to automate workflows involving Notion databases, pages, and other content.

Installation

pip install airflow-provider-notion

Configuration

  1. Get your Notion API token from Notion Integrations
  2. Set the connection in Airflow:
    • Connection ID: notion_default
    • Connection Type: Notion (或 HTTP)
    • Password: YOUR_NOTION_API_TOKEN (格式: secret_xxxxx...)
    • Extra (可选): {"headers": {"Notion-Version": "2022-06-28"}}

配置方式

方法 1: Airflow UI

Admin → Connections → Add Connection
- Connection Id: notion_default
- Connection Type: Notion
- Password: secret_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

方法 2: 环境变量

export AIRFLOW_CONN_NOTION_DEFAULT='{"conn_type": "notion", "password": "secret_YOUR_TOKEN"}'

方法 3: Airflow CLI

airflow connections add notion_default \
    --conn-type notion \
    --conn-password secret_YOUR_NOTION_TOKEN

Operators

NotionQueryDatabaseOperator

Query a Notion database and return the results.

from airflow.providers.nion.operators import NotionQueryDatabaseOperator

query_database = NotionQueryDatabaseOperator(
    task_id='query_notion_database',
    database_id='your-database-id',
    filter_params={
        'property': 'Status',
        'select': {
            'equals': 'Done'
        }
    },
    dag=dag
)

NotionCreatePageOperator

Create a new page in Notion.

from airflow.providers.nion.operators import NotionCreatePageOperator

create_page = NotionCreatePageOperator(
    task_id='create_notion_page',
    database_id='your-database-id',
    properties={
        'Title': {
            'title': [
                {
                    'text': {
                        'content': 'New Task'
                    }
                }
            ]
        },
        'Status': {
            'select': {
                'name': 'In Progress'
            }
        }
    },
    dag=dag
)

NotionUpdatePageOperator

Update an existing Notion page.

from airflow.providers.nion.operators import NotionUpdatePageOperator

update_page = NotionUpdatePageOperator(
    task_id='update_notion_page',
    page_id='your-page-id',
    properties={
        'Status': {
            'select': {
                'name': 'Completed'
            }
        }
    },
    dag=dag
)

Hooks

NotionHook

The base hook for interacting with Notion API.

from airflow.providers.nion.hooks import NotionHook

hook = NotionHook(notion_conn_id='notion_default')
# Query database
database = hook.get_database('database-id')
# Create page
page = hook.create_page(database_id='database-id', properties={...})
# Update page
page = hook.update_page(page_id='page-id', properties={...})

Development

Install development dependencies:

pip install -e ".[dev]"

Run tests:

pytest tests/

Format code:

black airflow/

Check types:

mypy airflow/

License

Apache License 2.0

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

airflow_provider_notion-0.0.1.tar.gz (29.8 kB view details)

Uploaded Source

Built Distribution

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

airflow_provider_notion-0.0.1-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

File details

Details for the file airflow_provider_notion-0.0.1.tar.gz.

File metadata

  • Download URL: airflow_provider_notion-0.0.1.tar.gz
  • Upload date:
  • Size: 29.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.18

File hashes

Hashes for airflow_provider_notion-0.0.1.tar.gz
Algorithm Hash digest
SHA256 cc4f69bb62968be07c81f67ded361a07c87b5d1c218cd369ec16e51d665385ac
MD5 b902ef7dc81b584d33676f0ffdc26f1a
BLAKE2b-256 b1b6929eda6f1768c02308779037034861707a68301c85938d13efd8fe43e2e6

See more details on using hashes here.

File details

Details for the file airflow_provider_notion-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for airflow_provider_notion-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f9af27728dd227f622b45591e0e57d66ab5d6e1a0e8d231c55ae8ecc7ba63ef2
MD5 356ea56c8806d69356ffa42802a7f3c2
BLAKE2b-256 830a05cee92ae8b5640fe6c32472646ce111b14d52af0e4061d0d6fd960041c3

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