{"library":"notion2md","title":"Notion to Markdown Exporter","description":"notion2md is a Python CLI tool designed to export Notion pages, databases, and blocks into markdown files. It leverages the Notion API client to fetch content and convert it into a standard markdown format. The current version is 2.9.0, and the project has an active, though irregular, release cadence with recent updates.","language":"python","status":"active","last_verified":"Fri Apr 17","install":{"commands":["pip install notion2md"],"cli":{"name":"notion2md","version":"Notion2Md (version 2.9.0)"}},"imports":["from notion2md.exporter import notion_to_markdown"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import os\nimport subprocess\n\n# Set your Notion API token as an environment variable\n# Ensure the token has read access to the page/database you intend to export.\n# Example: export NOTION_TOKEN=\"secret_YOUR_NOTION_TOKEN\"\n# For quick testing, you can set it directly (NOT recommended for production):\n# os.environ['NOTION_TOKEN'] = 'secret_YOUR_NOTION_TOKEN'\n\n# Replace with your actual Notion Page ID\nNOTION_PAGE_ID = os.environ.get('NOTION_PAGE_ID', 'a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6')\n\nif not os.environ.get('NOTION_TOKEN'):\n    print(\"Error: NOTION_TOKEN environment variable is not set.\")\n    print(\"Please set it (e.g., export NOTION_TOKEN='secret_YOUR_TOKEN')\")\nelse:\n    print(f\"Attempting to export Notion Page ID: {NOTION_PAGE_ID}...\")\n    try:\n        # Example CLI usage: Export a Notion page to a local 'output' directory\n        result = subprocess.run(\n            ['notion2md', NOTION_PAGE_ID, '-o', 'output'],\n            capture_output=True, text=True, check=True\n        )\n        print(\"Export successful!\")\n        print(\"STDOUT:\", result.stdout)\n        if result.stderr:\n            print(\"STDERR:\", result.stderr)\n    except subprocess.CalledProcessError as e:\n        print(f\"Error during export: {e}\")\n        print(\"STDOUT:\", e.stdout)\n        print(\"STDERR:\", e.stderr)\n    except FileNotFoundError:\n        print(\"Error: 'notion2md' command not found. Please ensure the package is installed and in your PATH.\")","lang":"python","description":"The primary use case for notion2md is via its command-line interface. This quickstart demonstrates how to export a Notion page by setting the `NOTION_TOKEN` environment variable and executing the `notion2md` command with a page ID and an output directory. Ensure your Notion API token has the necessary read permissions.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}