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
Configuration
Environment Variables
NOTION_TOKEN: Your Notion integration tokenNOTION_PARENT_IDS: Comma-separated list of parent page IDs
Config Object
The Config class accepts the following parameters:
notion_client: A configured Notion client instanceparent_ids: List of Notion page IDs to syncoutput_dir: Directory where markdown files will be savedrequired_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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file notion_git_sync-0.1.3.tar.gz.
File metadata
- Download URL: notion_git_sync-0.1.3.tar.gz
- Upload date:
- Size: 15.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
170b2e581fda51415d6a6af12f68c1095567a29927dacbd8c24264982eca2e26
|
|
| MD5 |
13d296247f37cdb5e947722a1be0df60
|
|
| BLAKE2b-256 |
322c13fa980e50f79e8380b9cd10a314f4e5d77dbeadc7f0ce59fe002c387cd6
|
File details
Details for the file notion_git_sync-0.1.3-py3-none-any.whl.
File metadata
- Download URL: notion_git_sync-0.1.3-py3-none-any.whl
- Upload date:
- Size: 12.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c78e77da7ee7335151966a2349f4ea17180b7f7d21b972545eef06c12c3d1ce
|
|
| MD5 |
e36aa0b95179925a86f29c2fbbc8ab32
|
|
| BLAKE2b-256 |
8b0a00a6351a9ffe63df166306ff1cf9af1f714069acd6d977600b7ba860fffe
|