Skip to main content

gmail-invoice

Download purchase invoice emails and PDF attachments from Gmail (read-only).

For a given date, the tool searches Gmail's Purchases category, saves each email as JSON, downloads any PDF attachments, and uses an LLM to extract structured invoice fields into the same JSON file.

Install

pip install gmail-invoice

Setup

  1. Create a Google Cloud OAuth desktop client with the Gmail API enabled and download credentials.json.

  2. Create a config folder outside this project (so credentials are not in your repo or workspace):

    mkdir -p ~/.config/gmail-invoice
    mv ~/Downloads/credentials.json ~/.config/gmail-invoice/
    
  3. Copy the sample env file, paste your config folder path, and save as .env:

    cp .env.example .env
    
    # .env — do not commit; do not share with AI assistants
    CONFIG_DIR=/Users/you/.config/gmail-invoice
    
    # Optional: where to write invoice folders (default: ./invoices_YYYY_MM_DD)
    # GMAIL_INVOICE_OUTPUT_DIR=./invoices_2026_05_24
    

    Replace /Users/you with your username (or use the full expanded path to ~/.config/gmail-invoice). On first run, OAuth will create token.json in that config folder.

  4. Add LLM settings in your config folder for invoice parsing:

    Anthropic (default) — sends PDFs natively and uses structured outputs:

    cat > ~/.config/gmail-invoice/llm.env <<'EOF'
    LLM_PROVIDER=anthropic
    LLM_API_KEY=sk-ant-api03-your-key-here
    LLM_MODEL=claude-sonnet-4-6
    EOF
    

    OpenAI-compatible (OpenAI, Groq, Together, Ollama shim, etc.):

    cat > ~/.config/gmail-invoice/llm.env <<'EOF'
    LLM_PROVIDER=openai
    LLM_API_KEY=sk-your-key-here
    LLM_BASE_URL=https://api.openai.com/v1
    LLM_MODEL=gpt-4o-mini
    EOF
    

Usage

# Today's purchase emails → ./invoices_YYYY_MM_DD/
gmail-invoice

# Specific date
gmail-invoice --date 2026-05-04

# Download only — skip LLM parsing
gmail-invoice --date 2026-05-04 --skip-parse

Equivalent module invocation:

python -m gmail_invoice --date 2026-05-04

Output

Each run creates a folder (default: invoices_YYYY_MM_DD/ in the current directory) containing:

  • email_YYYY_MM_DD_HH_MM_SS.json — sender, subject, body text, and parsed invoice object
  • *.pdf — invoice attachments with a timestamp suffix

Example invoice fields in the JSON:

{
  "is_invoice": true,
  "vendor_name": "Apple",
  "invoice_number": "INV-2026-9912",
  "invoice_date": "2026-05-22",
  "currency": "USD",
  "subtotal": 1199.0,
  "tax": 100.0,
  "total": 1299.0,
  "line_items": [{"description": "MacBook", "quantity": 1, "unit_price": 1199.0, "amount": 1199.0}]
}

Development

git clone https://github.com/nishat-khan/gmail-invoice.git
cd gmail-invoice
pip install -e ".[dev]"
pytest
ruff check .
gmail-invoice --date 2026-05-04

License

MIT

Metadata

Release files for gmail-invoice 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gmail-invoice 0.2.1
File Size Uploaded Provenance Actions
gmail_invoice-0.2.1.tar.gz 14.3 kB Without provenance Details for gmail_invoice-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for gmail-invoice 0.2.1
File Interpreter ABI Platform Actions
gmail_invoice-0.2.1-py3-none-any.whl Python 3 none any Details for gmail_invoice-0.2.1-py3-none-any.whl

Total release size: 26.3 kB

Release files / gmail_invoice-0.2.1.tar.gz

Download URL gmail_invoice-0.2.1.tar.gz
Size 14.3 kB
Tags Source
SHA-256 checksum
How to use checksums
60892cde5a171e277179d9ccc22c57b02bd7c9ecc32568179b3d188a1fc989a5
BLAKE2b-256 checksum
How to use checksums
245121b95d9bfcd957a2cb1292b6b2a656c951167bd452c22844c0e5b3f50fdb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Release files / gmail_invoice-0.2.1-py3-none-any.whl

Download URL gmail_invoice-0.2.1-py3-none-any.whl
Size 12.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
851a85b18a784f96813b82ad28d282057e7c0da1ee7654cbc0a744bf66f2f890
BLAKE2b-256 checksum
How to use checksums
68423760128b04ecf4f8644415cd154abcdadd78067cde0cfff2efeb49e7ed3c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Security for gmail-invoice 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page