Skip to main content

SQLite Export for YNAB - Export YNAB Budget Data to SQLite

Project description

sqlite-export-for-ynab

pre-commit.ci status

SQLite Export for YNAB - Export YNAB Budget Data to SQLite

What this Does

Export your YNAB budget to a local SQLite DB

Installation

$ pip install sqlite-export-for-ynab

Usage

Run it from the terminal to download your budget:

$ sqlite-export-for-ynab

Running it again will pull only the data that changed since the last pull. If you want to wipe the DB and pull all data again use the --full-refresh flag.

The DB is stored according to the XDG Base Directory Specification.

By default the DB is saved in "${XDG_DATA_HOME}"/sqlite-export-for-ynab/db.sqlite. If you don't set XDG_DATA_HOME then by default the DB will be saved in ~/.local/share/sqlite-export-for-ynab/db.sqlite.

Use the --db argument to specify a different DB path.

SQL

The schema is defined in create-tables.sql. It is very similar to YNAB's OpenAPI Spec however some objects are pulled out into their own tables (ex: subtransactions, loan account periodic values) and foreign keys are added as needed (ex: budget ID, transaction ID).

You can query the DB with typical SQLite tools. For example, to get the top 5 payees by spending per budget, you could do:

WITH
    ranked_payees AS (
        SELECT
            b.name AS budget_name,
            p.name AS payee,
            SUM(t.amount) / -1000.0 AS net_spent,
            ROW_NUMBER() OVER (
                PARTITION BY
                    b.id
                ORDER BY
                    SUM(t.amount) ASC
            ) AS rnk
        FROM
            transactions t
            JOIN payees p ON t.payee_id = p.id
            JOIN budgets b ON t.budget_id = b.id
        WHERE
            p.name != 'Starting Balance'
            AND p.transfer_account_id IS NULL
        GROUP BY
            b.id,
            p.id
    )
SELECT
    budget_name,
    payee,
    net_spent
FROM
    ranked_payees
WHERE
    rnk <= 5
ORDER BY
    budget_name,
    net_spent DESC
;

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sqlite_export_for_ynab-0.0.3.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

sqlite_export_for_ynab-0.0.3-py2.py3-none-any.whl (8.6 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file sqlite_export_for_ynab-0.0.3.tar.gz.

File metadata

File hashes

Hashes for sqlite_export_for_ynab-0.0.3.tar.gz
Algorithm Hash digest
SHA256 53dd7279593124a03b20dfc8d83b7ecc5ad5698c0187894fce2a4adc889a2396
MD5 656eb50d7189a2dcfa89c8a96fe54dc9
BLAKE2b-256 ab0f5046a9bc912ca98cce26e2b68539bd13b586412ed2d8d86cfb34d13658d5

See more details on using hashes here.

File details

Details for the file sqlite_export_for_ynab-0.0.3-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for sqlite_export_for_ynab-0.0.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 21cc8dffbb0fbae5974e879263dd4a648471d944700f6631678fc3ea4118d560
MD5 586bab1a19e7c0aecba21c7a0e3f9d67
BLAKE2b-256 8e44e6fe8c912e765eacbb1fce4f5903b7b7604fca588f44def7aadf84ed53bc

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page