Python script that synchronizes flagged transactions from You Need A Budget (YNAB) to Splitwise.
It supports multiple account configurations and is designed to be run as a cron job at least once a day.
The script uses the YNAB and Splitwise APIs to perform the synchronization. It first fetches all transactions from YNAB for the past day and filters the ones flagged with a blue color. For each of these transactions, it creates an expense in Splitwise. If the expense is successfully created, the transaction is marked as synchronized in YNAB by setting the flag color to green.
When a transaction is successfully synced to Splitwise, its amount is automatically split in YNAB:
- 50% remains in the original budget category
- 50% is moved to a "Splitwise" category (which is created automatically if it doesn't exist)
This split categorization helps track shared expenses in your budget while maintaining accurate category spending records.
- Clone this repository to your local machine.
- Create a config.yml file in the root directory of the project with the following structure:
accounts: - name: Account 1 ynab_api_key: YOUR_YNAB_API_KEY budget_id: YOUR_YNAB_BUDGET_ID splitwise_api_key: YOUR_SPLITWISE_API_KEY group_id: YOUR_SPLITWISE_GROUP_ID - name: Account 2 # Optional ynab_api_key: YOUR_YNAB_API_KEY budget_id: YOUR_YNAB_BUDGET_ID splitwise_api_key: YOUR_SPLITWISE_API_KEY group_id: YOUR_SPLITWISE_GROUP_ID
- Replace YOUR_YNAB_API_KEY, YOUR_YNAB_BUDGET_ID, YOUR_SPLITWISE_API_KEY, and YOUR_SPLITWISE_GROUP_ID with your actual API keys and IDs.
This project uses poetry to manage its dependencies.
You can use this setup to locally develop and test this script. It will build the docker image and mount the code as a volume in the container.
docker-compose up
This docker-compose file uses the registry to pull the image and mount only the configuration file.
docker-compose -f docker-compose.prod.yml up
Alternatively you can use a docker command directly:
docker run -v ./config.yml:/app/config.yml ghcr.io/gperiard/ynab2splitwise:latest
If you've been using this script before the category split feature was added, you can use the backfill script to split all previously synced transactions.
# Preview changes without making them
docker-compose run --rm syncer python ynab2splitwise/backfill.py --dry-run
# Actually perform the backfill
docker-compose run --rm syncer python ynab2splitwise/backfill.py
# Preview changes without making them
python ynab2splitwise/backfill.py --dry-run
# Actually perform the backfill
python ynab2splitwise/backfill.py
The backfill script will:
- Find all transactions marked as synced (green flag)
- For any that don't already have split categories:
- Split the amount 50/50 between the original category and the Splitwise category
- Preserve all other transaction details
The script processes transactions in batches to avoid API limits and provides logging output to track progress. Using the --dry-run
option will show you exactly what changes would be made without actually making them, which is useful for reviewing the impact before committing the changes.
Ultimately, this script is meant to be run as a cronjob.
Here's a configuration example to run the script every hour:
0 * * * * docker run -v <CONFIGURATION PATH>:/app/config.yml ghcr.io/gperiard/ynab2splitwise:latest
There's an Ansible role in this project to simplify the configuration of the cronjob.
- Add this repo in your requirements.yml file:
roles: - src: https://github.com/gperiard/ynab2splitwise.git version: v0.2.0 name: ynab2splitwise
- Download it.
ansible-galaxy install -r requirements.yml
- Create a playbook. Here's an example:
# cronjobs.yml --- - hosts: cronjobs.periard.ca become: true vars_file: - vault.yml # <- contains your account configuration under y2s_accounts_configuration roles: - role: ynab2splitwise y2s_config_dir: /opt/docker/ynab2splitwise
- Run it.
ansible-playbook -i inventory cronjobs.yml
Pull requests are welcome.
This project is licensed under the GNU GPLv3 License - see the LICENSE file for details.