Automated scripts for syncing Pipedrive CRM data to Notion databases, providing real-time KPI tracking for sales performance.
Syncs KPI data from Pipedrive to a Notion database, tracking weekly performance metrics for your sales team:
- New Qualified Opps - Deals that reached qualified status
- Meetings On Calendar - Scheduled meetings for the week
- Meetings Scheduled - New meetings added
- Meetings Conducted - Completed meetings
- Proposal Follow-Up - Proposal follow-up activities completed
- Revenue Closed - Dollar value of deals invoiced
✅ Automatic Updates - Runs twice daily (midnight & noon Pacific) ✅ Historical Data - Backfill script for past weeks ✅ Weekly Tracking - Sunday-Saturday weeks to match Pipedrive ✅ Goal Tracking - Pulls goals from separate Goals database ✅ Smart Updates - Updates existing week data, creates new rows on Sundays only
- Python 3.11+
- Notion account with API access
- Pipedrive account with API access
- GitHub repository (for automated runs)
-
Clone the repository
git clone https://github.com/yourusername/SCPCC-Notion.git cd SCPCC-Notion -
Install dependencies
cd scripts/pipedrive pip install -r requirements.txt -
Configure environment
cp config/example.env .env # Edit .env with your actual API tokens -
Run the sync
source .env # Load environment variables python sync_kpis.py
Create a .env file in the project root with these values:
# Notion Configuration
NOTION_API_TOKEN=your_notion_api_token_here
KPI_NOTION_DATABASE_ID=your_kpi_database_id_here
# Pipedrive Configuration
PIPEDRIVE_API_TOKEN=your_pipedrive_api_token_here
# Optional Configuration
TIMEZONE=America/Los_AngelesFor automated runs via GitHub Actions, add these secrets to your repository:
- Go to Settings → Secrets and variables → Actions
- Add the following secrets:
NOTION_API_TOKENKPI_NOTION_DATABASE_IDPIPEDRIVE_API_TOKENTIMEZONE(optional, defaults to America/Denver)
SCPCC-Notion/
├── .github/workflows/
│ ├── kpi-sync.yml # Automated sync (runs 2x daily)
│ └── lint.yml # Code quality checks
├── config/
│ └── example.env # Example environment variables
├── docs/
│ └── kpi-sync.md # Detailed documentation
├── scripts/
│ └── pipedrive/
│ ├── sync_kpis.py # Main sync script (updates/creates rows)
│ ├── backfill_weeks.py # Historical data backfill
│ ├── init_database.py # Initialize database with rows
│ ├── utils.py # Shared utilities
│ ├── mappings.py # Salesperson & activity mappings
│ └── requirements.txt # Python dependencies
└── README.md
Purpose: Daily sync that updates current week data or creates new week rows on Sundays.
Usage:
cd scripts/pipedrive
python sync_kpis.pyBehavior:
- Monday-Saturday: Updates existing 18 rows for current week
- Sunday: Creates 18 new rows for the new week
- Fetches fresh data from Pipedrive twice daily
Purpose: One-time script to populate historical KPI data for all weeks in the current year.
Usage:
cd scripts/pipedrive
python backfill_weeks.pyOutput: Creates rows for every week from Jan 1 to present (e.g., 41 weeks × 3 salespeople × 6 KPIs = 738 rows)
Purpose: Creates initial rows in Notion database for testing.
Usage:
cd scripts/pipedrive
python init_database.pyNote: Only needed for initial setup or testing. sync_kpis.py handles ongoing row creation.
Your Notion KPI database must have these properties:
| Property Name | Type | Description |
|---|---|---|
| KPI | Title | KPI name (e.g., "Revenue Closed") |
| Salesperson | Rich Text | Salesperson name |
| Week | Date | Sunday date of the week (YYYY-MM-DD) |
| Current | Number | Current value for the KPI |
| Goal | Number | Goal value for the KPI |
| Last Sync | Date | Timestamp of last update |
Create a separate Goals database with:
| Property Name | Type | Description |
|---|---|---|
| Name | Title | Salesperson name |
| New Qualified Opps | Number | Weekly goal |
| Meetings On Calendar | Number | Weekly goal |
| Meetings Scheduled | Number | Weekly goal |
| Meetings Conducted | Number | Weekly goal |
| Proposal Follow-Up | Number | Weekly goal |
| Revenue Closed | Number | Weekly goal (in dollars) |
What it measures: Count of deals that reached "qualified" status during the week.
Data source: Pipedrive custom field "Date Qualified (Later Part of Sales Pipeline)"
Logic: Counts deals where qualified date falls within the week range.
What it measures: Number of meetings scheduled to occur during the week.
Data source: Pipedrive activities with types:
- "Meeting - Qualify"
- "Meeting - Discovery"
- "Meeting - Engage/Data Review"
- "Meeting - Learn/Project Review"
Logic: Counts activities where due_date falls within the week.
What it measures: Number of new meetings added during the week.
Data source: Same meeting activity types as above.
Logic: Counts activities where add_time (creation date) falls within the week.
What it measures: Number of meetings completed during the week.
Data source: Same meeting activity types as above.
Logic: Counts activities marked as done where marked_as_done_time falls within the week.
What it measures: Number of proposal follow-up activities completed.
Data source: Pipedrive activities with type "Proposal Follow-up"
Logic: Counts activities marked as done where marked_as_done_time falls within the week.
What it measures: Total dollar value of deals invoiced during the week.
Data source: Pipedrive deals in "Invoiced (Current)" stage (Stage ID: 101)
Logic: Sums deal values where:
- Deal entered "Invoiced (Current)" stage during the week
- Deal status is "open" or "won" (not lost/deleted)
The workflow runs automatically:
- 12:00 AM PST (midnight)
- 12:00 PM PST (noon)
Run the sync manually:
- Go to Actions tab in GitHub
- Select "KPI Sync (Pipedrive → Notion)"
- Click "Run workflow"
Update scripts/pipedrive/mappings.py to map your Notion names to Pipedrive users:
SALESPERSON_TO_PD_USER = {
"Daniel Rico": "Daniel Rico",
"Shasta Wickham": "Shasta Wickham",
"Isaac Lopez": "Isaac Lopez",
}- Verify your Notion integration has access to both databases
- Check that database IDs are correct (copy from database URL)
- Ensure environment variables are loaded:
source .env - Check that
.envfile exists and has correct values
- Weeks run Sunday-Saturday to match Pipedrive
- Week field shows the Sunday date (start of week)
- Run
init_database.pyfirst to create initial rows - Check that Pipedrive API token has correct permissions
- Verify salesperson names match exactly in mappings.py
-
Create a feature branch
git checkout -b feature/your-feature-name
-
Make your changes
# Edit files -
Format code
black scripts/ ruff check scripts/
-
Test locally
cd scripts/pipedrive python sync_kpis.py -
Commit and push
git add . git commit -m "feat(sync): your description" git push origin feature/your-feature-name
- Python: Black formatter, Ruff linter
- Commits: Conventional commits format
- Branches:
feature/,fix/,docs/prefixes
MIT License - See LICENSE file for details
- Fork the repository
- Create a feature branch
- Make your changes
- Run linting and formatting
- Submit a pull request
For issues or questions:
- Open a GitHub issue
- Check the docs folder for detailed runbooks
- Review the troubleshooting section above
Built with ❤️ for sales team performance tracking