Skip to main content

NotionDL

Designed to simplify the process of exporting content from Notion. It provides an interface to configure, trigger, and download content exports from Notion. The class supports exporting content in various formats (Markdown, HTML, PDF) and also allows users to choose the scope of the export (current view vs. all content).

Features

  • Export content in Markdown, HTML, or PDF format.
  • Configure the scope of your export: current view or all content.
  • Option to include or exclude files in the export.
  • Flatten the file tree structure upon export.
  • Export multiple pages concurrently for faster processing.
  • Monitor export progress with a progress bar.
  • Automatically unpack zipped export files.

Installation

pip install notiondl

Usage

CLI

python -m notiondl <PAGE_ID> -t <EXPORT_TYPE> --no-file -v

Avaialbe Options

Argument Description
PAGE_ID (required) The ID of the Notion page you want to export. Separate multiple pages with commas.
-d, --export-dir The directory to export the page to. Defaults to the current directory.
-t, --export-type The type of file to export. Defaults to HTML.
-l, --no-file Do not export files attached to the page. Defaults to False.
-k, -keep-structure Keep the page hierarchy when exporting. Defaults to False.
-s, --single-page Do not export child pages. Defaults to False.
-w, --rewrite Do not create date-formated folders for each export. Defaults to False.
-v, --verbose Whether to print verbose output. Defaults to False.
-c, --current-view The type of view to export. Defaults to the currentView.
You can set whether NOTION_TOKEN_V2 and NOTION_FILE_TOKEN environment variables or providing these as CLI arguments.
--token-v2 The token_v2 cookie value from your Notion session.
--file-token The file-token cookie value from your Notion session.

Python

import notiondl

exporter = notiondl.NotionExporter(
    token_v2="<TOKEN>",
    file_token="<FILE_TOKEN>",
    pages={"index.html": "<PAGE_ID>"},
    export_directory="test",
    flatten_export_file_tree=True,
    export_type=notiondl.ExportType.HTML,
    current_view_export_type=notiondl.ViewExportType.CURRENT_VIEW,
    include_files=True,
    recursive=True,
    rewrite=True,
)
exporter.export()

Requirements

In case of CLI, you have to set NOTION_TOKEN_V2 and NOTION_FILE_TOKEN environment variables. You will need to get the token_v2 and file_token values from your Notion cookies. The pages dictionary should contain pairs of page_name: page_id for each page you want to export. page_name can be anything and would be used for the final downloaded file name.

Needed Cookies

To export anything from Notion, one needs to authenticate oneself with some Cookies (like a browser would). These cookies are called token_v2 and file_token. They are set on all requests of a logged in user when using the Notion web-app.

How to retrieve the Cookies?

  • Go to notion.so.
  • Log in with your account.
  • Open the developer tools of your browser, open Application > Storage > Cookies (Chrome); Storage tab (Firefox).
  • Copy the value of the Cookies called token_v2 and file_token and paste them somewhere safe.
  • ⚠️ If you don't find file_token, you need to have at least had exported a file manually once.
  • Those cookies have a 1 year validity, so you don't need to do this often.

License

MIT

Acknowledgement

https://github.com/Strvm/python-notion-exporter

Metadata

Release files for notiondl 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for notiondl 0.2.1
File Size Uploaded
notiondl-0.2.1.tar.gz 7.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for notiondl 0.2.1
File Interpreter ABI Platform
notiondl-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 16.4 kB

Release files / notiondl-0.2.1.tar.gz

Download URL notiondl-0.2.1.tar.gz
Size 7.2 kB
Tags Source
SHA-256 checksum
How to use checksums
7f6e93730be416d3a55162bff764a50bac9ebbbf9ac0301ba8ff8304cf5b2c18
BLAKE2b-256 checksum
How to use checksums
4e87e9a67a4adc35eba1e6342bf95dbd3c38a7e9042b34c09f95639145e10788
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.6.1 CPython/3.11.5 Linux/5.15.0-1041-azure

Release files / notiondl-0.2.1-py3-none-any.whl

Download URL notiondl-0.2.1-py3-none-any.whl
Size 9.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
807478da7be6588a3c3edb549832f8e56f1cb8c577eec9d8f8441521d9f726ce
BLAKE2b-256 checksum
How to use checksums
5401853f17bbaf11d71c497e4623b9eb9bf92429405416870828acd7a7b77a88
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.6.1 CPython/3.11.5 Linux/5.15.0-1041-azure

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page