Skip to main content

Synchronize Notion pages to markdown files with frontmatter support

Project description

Notion Git Sync

Synchronize Notion pages to markdown files with frontmatter support.

Features

  • Converts Notion pages to markdown
  • Supports YAML frontmatter
  • Handles nested content
  • Git integration
  • Rich block type support
  • Automatic change detection
  • GitHub Actions integration

Installation

pip install notion-git-sync

Usage

As a Python Library (Recommended)

from notion_git_sync.sync import NotionSync, Config

# Create config from environment variables
config = Config.from_env()
# Or create config manually
config = Config(
    notion_client=notion_client,
    parent_ids=["page_id_1", "page_id_2"],
    output_dir="path/to/output",
    required_frontmatter={"title", "owner"}
)

# Initialize and run sync
syncer = NotionSync(config)
changed_files = syncer.sync()  # Returns list of changed files

As a Command Line Tool

The package includes a CLI script for simple use cases:

# Set environment variables
export NOTION_TOKEN="your_notion_token"
export NOTION_PARENT_IDS="page_id_1,page_id_2"

# Run the sync
python -m notion_git_sync.sync

GitHub Actions Integration

The package includes a GitHub Actions workflow for automated syncing:

name: notion-sync
on:
  schedule: [{ cron: '5 2 * * *' }]  # nightly 02:05 UTC
  workflow_dispatch:

jobs:
  sync:
    runs-on: ubuntu-latest
    env:
      NOTION_TOKEN: ${{ secrets.NOTION_TOKEN }}
      NOTION_PARENT_IDS: ${{ secrets.NOTION_PARENT_IDS }}
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
      - run: pip install notion-git-sync
      - run: python -m notion_git_sync.sync

Repository Configuration

The GitHub Actions workflow will push changes to the same repository where the workflow is running. Make sure to:

  1. Configure repository permissions to allow the workflow to push changes:

    • Go to your repository's Settings > Actions > General
    • Under "Workflow permissions", select "Read and write permissions"
    • Save the changes
  2. If you want to push to a different repository:

    • Add a Personal Access Token (PAT) with repo scope as a repository secret
    • Configure the remote URL in your workflow to use the PAT:
      - name: Configure Git
        run: |
          git config --global user.name "GitHub Actions"
          git config --global user.email "actions@github.com"
          git remote set-url origin https://${{ secrets.PAT }}@github.com/username/repo.git
      

Configuration

Environment Variables

  • NOTION_TOKEN: Your Notion integration token
  • NOTION_PARENT_IDS: Comma-separated list of parent page IDs

Config Object

The Config class accepts the following parameters:

  • notion_client: A configured Notion client instance
  • parent_ids: List of Notion page IDs to sync
  • output_dir: Directory where markdown files will be saved
  • required_frontmatter: Set of required frontmatter fields

Development

# Install development dependencies
pip install -e ".[dev]"

# Run tests
pytest tests/

License

MIT

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_git_sync-0.1.6.tar.gz (15.6 kB view details)

Uploaded Source

Built Distribution

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

notion_git_sync-0.1.6-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

Details for the file notion_git_sync-0.1.6.tar.gz.

File metadata

  • Download URL: notion_git_sync-0.1.6.tar.gz
  • Upload date:
  • Size: 15.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for notion_git_sync-0.1.6.tar.gz
Algorithm Hash digest
SHA256 45a93161549b59ec89c08042c231c57ad814be9068024ce2adf7e6122111e056
MD5 8a8b62ccc07a93102eceafb35586f275
BLAKE2b-256 336aacfeb68898e52d7a33b6096fe11841c658757e42a6a9e0aa6aa0f645b2cc

See more details on using hashes here.

File details

Details for the file notion_git_sync-0.1.6-py3-none-any.whl.

File metadata

File hashes

Hashes for notion_git_sync-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 5cbf51a6f4e74b82d650e1bfd00493f5f75a7e2e4db667cd35724a001a857cf8
MD5 253a4b9e559d88b59801b2649853198e
BLAKE2b-256 882186a8b681713503ed7ad72c5a38e50c22663f1869638ee476b3341afdb661

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