This is the Python implementation of nodejs version of notion-to-md, a tool that converts Notion pages into Markdown files.
Install the package via pip:
pip install notion-to-md-py
from notion_client import Client
from notion_to_md import NotionToMarkdown
notion = Client(auth="your-auth-token")
n2m = NotionToMarkdown(notion)
# Export a page as a markdown blocks
md_blocks = n2m.page_to_markdown("page-id")
# Convert markdown blocks to string
md_str = n2m.to_markdown_string(md_blocks).get('parent')
# Write to a file
with open("output.md", "w") as f:
f.write(md_str)
import asyncio
from notion_client import AsyncClient
from notion_to_md import NotionToMarkdownAsync
notion = AsyncClient(auth="your-auth-token")
n2m = NotionToMarkdownAsync(notion)
# Export a page as a markdown blocks
md_blocks = asyncio.run(n2m.page_to_markdown("page-id"))
# Convert markdown blocks to string
md_str = n2m.to_markdown_string(md_blocks).get('parent')
# Write to a file
with open("output.md", "w") as f:
f.write(md_str)
Replace your-auth-token
and page-id
with the appropriate values from your Notion account.
- Create an integration in your Notion account and get the
API key
. - Share your database with the integration to allow access.
- Retrieve your
Database ID
andPage ID
from the Notion app.
- Python 3.7 or later
- Notion API key
- The tool relies on the Notion API, and features are limited to what the API supports.
- Embedding or downloading files other than images is not supported.
Contributions are welcome! Feel free to open issues or submit pull requests to improve the functionality or fix bugs.
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Submit a pull request with a clear description of your changes.
This project is licensed under the MIT License.