Spaces:
Running
A newer version of the Gradio SDK is available: 6.20.0
title: Notion DB Export Tool
sdk: gradio
emoji: π»
colorFrom: yellow
colorTo: green
sdk_version: 5.49.1
Notion Excel Exporter - Hugging Face Spaces
A secure web application for exporting Notion databases to Excel format with three specialized export modes.
Features
- 3 Export Modes with Separate Tabs:
- Notion Databases: Export raw Notion database tables with all properties
- Entry Milestones: Export entry milestone tracking data with CBP/CPSC status
- MAWB Milestones: Export aggregated SHEIN T01 MAWB milestone data
- Date Filtering: Filter records by
created_time(when records were created in Notion) - MAWB Number Input: Specify specific MAWBs to export (comma or newline separated)
- Rate Limiting Protection: Slow mode and configurable page sizes to prevent API throttling
- Secure Authentication: Username/password login required
- Multi-Sheet Excel: Exports multiple databases into a single Excel file with separate sheets
- Real-time Progress: Shows export status and processing information
- Export-Only: Does not modify any Notion records (no task auto-checking)
Supported Databases
- MAWB (Master Air Waybill)
- Entry Records
- MAWB Tasks
- MAWB Milestones (Warehouse milestone records)
- Dwell Report
Deployment to Hugging Face Spaces
Step 1: Create a New Space
- Go to Hugging Face Spaces
- Click "Create new Space"
- Configure:
- Space name:
notion-excel-exporter(or your preferred name) - SDK: Select
Gradio - Hardware:
CPU Basic(free tier is sufficient) - Visibility:
Private(recommended for security)
- Space name:
Step 2: Upload Files
Upload the following files to your Space:
app.py
notion_exporter.py
entry_milestone_exporter.py
mawb_milestone_exporter.py
requirements.txt
README.md
src/
βββ notion_integration.py
You can either:
- Use the web interface to drag and drop files
- Clone the Space repository and push via git:
git clone https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME cd YOUR_SPACE_NAME # Copy all files from huggingface-notion-export/ folder git add . git commit -m "Initial deployment" git push
Step 3: Configure Environment Secrets
Go to your Space Settings > Variables and secrets > Add a secret.
Add the following secrets (click "New secret" for each):
Required Notion Configuration:
NOTION_API_KEY- Your Notion integration API keyMAWB_DB_ID- MAWB database ID (format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)ENTRY_RECORD_DB_ID- Entry Record database IDMAWB_TASK_DB_ID- MAWB Task database IDMAWB_MILESTONE_DB_ID- MAWB Milestone database IDDWELL_REPORT_DB_ID- Dwell Report database ID (optional)
Authentication Credentials:
HF_USERNAME- Login username for the appHF_PASSWORD- Login password for the app
Important Notes:
- Database IDs should include dashes (format:
247f8938-365a-80d4-bdd1-d9de191b7c05) - All secrets are stored securely and never exposed in logs
- You can skip optional database IDs if not needed
Step 4: Verify Deployment
- Wait for the Space to build (usually 2-5 minutes)
- Once running, click the app URL
- Enter your credentials (HF_USERNAME and HF_PASSWORD)
- Test export with a single database first
Getting Notion API Credentials
Notion API Key
- Go to Notion Developers
- Click "New integration"
- Name it (e.g., "Excel Exporter")
- Select the workspace
- Copy the "Internal Integration Token" (starts with
secret_)
Database IDs
- Open your Notion database in browser
- Copy the URL, which looks like:
https://www.notion.so/workspace/xxxxxxxxxx?v=yyyyyyyy - The database ID is the part after the last slash and before the
? - Format:
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx(with dashes)
Grant Access to Databases
For each database:
- Open the database in Notion
- Click the
...menu in the top right - Select "Add connections"
- Find and select your integration
- Click "Confirm"
Usage Instructions
Tab 1: Notion Databases
Export raw Notion database tables with all properties automatically captured.
- Select Databases: Check one or more databases (MAWB, Entry Records, Tasks, Milestones, Dwell Report)
- Set Date Filter (Optional):
- Filters by
created_time(when the record was created in Notion) - Enter start date in
YYYY-MM-DDformat (e.g.,2024-01-01) - Enter end date in
YYYY-MM-DDformat (e.g.,2024-12-31)
- Filters by
- Configure Options:
- Enable "Slow Mode" for large exports or if you encounter rate limits
- Adjust "Page Size" (lower = safer, higher = faster)
- Click Export: Wait for processing to complete
- Download: Click the file link to download your Excel file
Tab 2: Entry Milestones
Export entry milestone tracking data with CBP and CPSC status information.
- MAWB Numbers (Optional):
- Leave empty to export all entry records
- Or enter specific MAWBs (one per line or comma-separated)
- Example:
369-95208794, 370-12345678
- Set Date Filter (Optional):
- Filters by entry record
created_time - Enter start/end dates in
YYYY-MM-DDformat
- Filters by entry record
- Click Export: Wait for processing to complete
- Download: Excel file includes Entry, MAWB, POD, CBP Line, CPSC Line, release dates, etc.
Tab 3: MAWB Milestones (SHEIN T01)
Export aggregated milestone data for SHEIN T01 MAWBs (one row per MAWB).
- MAWB Numbers (Optional):
- Leave empty to export all SHEIN T01 MAWBs
- Or enter specific MAWBs (one per line or comma-separated)
- Set Date Filter (Optional):
- Filters by MAWB record
created_time - Enter start/end dates in
YYYY-MM-DDformat
- Filters by MAWB record
- Click Export: Wait for processing to complete
- Download: Excel file includes aggregated data across all related entries and warehouse milestone records per MAWB
Export Output
Tab 1: Notion Databases Export
- Single Database:
notion_{database_name}_{timestamp}.xlsx- Single sheet with database name
- Multiple Databases:
notion_export_{timestamp}.xlsx- Multiple sheets: "MAWB Data", "Entry Records", "MAWB Tasks", "MAWB Milestones", "Dwell Report"
Tab 2: Entry Milestones Export
- All Entries:
entry_milestone_export_all_{timestamp}.xlsx - Specific MAWBs:
entry_milestone_export_specific_{timestamp}.xlsx - Sheet: "Entry Milestone Export"
- Columns: MAWB, Entry, POD, handover_doc, CBP Line, CBP_release, CPSC Line, CPSC_check, CPSC_release, released, etc.
Tab 3: MAWB Milestones Export
- All SHEIN T01:
mawb_milestone_export_all_{timestamp}.xlsx - Specific MAWBs:
mawb_milestone_export_specific_{timestamp}.xlsx - Sheet: "SHEIN_T01_MAWB_Milestones"
- Columns: MAWB, T01 Entry Submission, PDA scan, T01 CBP Exam, T01 CBP Release, T01 CPSC/PGA Review, T01 CPSC/PGA release, Customs Release, Cargo ready for pickup, Ship out completed, XC shipment list PCS, MAWB POD
Troubleshooting
Rate Limiting Errors
Symptom: Export fails with "429 Too Many Requests" or rate limit errors
Solutions:
- Enable "Slow Mode" checkbox
- Reduce page size to 25-35
- Export fewer databases at once
- Wait a few minutes before retrying
Authentication Failed
Symptom: Cannot login to the app
Solutions:
- Verify
HF_USERNAMEandHF_PASSWORDare set correctly in Space secrets - Check for typos in credentials
- Restart the Space (Settings > Factory reboot)
Missing Database
Symptom: Error message about missing database ID
Solutions:
- Verify the database ID is set in Space secrets
- Check the database ID format (must include dashes)
- Ensure the integration has access to the database in Notion
Empty Export
Symptom: Excel file is generated but has no data
Solutions:
- Check date filters (may be filtering out all records)
- Verify the database actually has records in Notion
- Ensure the integration has proper permissions
API Rate Limits
Notion API has rate limits:
- 3 requests per second per integration
- Burst protection: Can queue up to 10 requests
The exporter handles rate limits with:
- Automatic delays between requests (0.5-1.5s normal, 2-4s slow mode)
- Exponential backoff on 429 errors (60s, 120s, 240s, 480s)
- Configurable page sizes to reduce total API calls
Security Best Practices
- Keep Space Private: Set visibility to "Private" in Space settings
- Strong Password: Use a complex password for HF_PASSWORD
- Rotate Credentials: Periodically update Notion API key and app password
- Monitor Access: Check Space logs for suspicious activity
- Least Privilege: Only grant integration access to required databases
Project Structure
huggingface-notion-export/
βββ app.py # Gradio web interface with 3 tabs
βββ notion_exporter.py # Notion database export logic
βββ entry_milestone_exporter.py # Entry milestone export logic
βββ mawb_milestone_exporter.py # MAWB milestone export logic (SHEIN T01)
βββ src/
β βββ notion_integration.py # Notion API integration
βββ requirements.txt # Python dependencies
βββ README.md # This file
βββ .gitignore # Git ignore rules
Local Development
To test locally before deploying:
# Clone the repository
git clone <repo-url>
cd huggingface-notion-export
# Install dependencies
pip install -r requirements.txt
# Set environment variables (create .env file)
export NOTION_API_KEY=your_key
export MAWB_DB_ID=your_db_id
export ENTRY_RECORD_DB_ID=your_db_id
export MAWB_TASK_DB_ID=your_db_id
export MAWB_MILESTONE_DB_ID=your_db_id
export HF_USERNAME=admin
export HF_PASSWORD=password
# Run the app
python app.py
Visit http://127.0.0.1:7860 in your browser.
Support
For issues or questions:
- Check the troubleshooting section above
- Review Hugging Face Spaces documentation
- Verify Notion API integration settings
License
This project is for internal use only.
Version
- Version: 2.0.0
- Last Updated: 2025-10-22
- Notion API Version: 2025-09-03
- New in v2.0: Added Entry Milestone and MAWB Milestone export modes with MAWB input filtering