# Python PDF invoice generator

A billing desk turns client and line item details into a polished PDF, assigns the next invoice number, and keeps recent files ready to download. Tokay runs the FastAPI app as one Web Service with persistent SQLite and document storage.

Use it when a browser action needs native document rendering and a durable local record. You declare normal Python packages while Tokay supplies the system libraries WeasyPrint needs.

## Facts

- Runtime: Python
- Framework: FastAPI and WeasyPrint
- Service types: Web Service
- Resources: SQLite, Persistent files
- Required secrets: None

## What it does

The page opens with a sample invoice for Marrowlight Studio and a form ready for a new client.

Enter up to three line items with quantities and rates, then press **Create PDF invoice**. The browser downloads a letter sized invoice with calculated totals and the next `JFI` number.

**Recent invoices** keeps the latest 12 files available by client, issue date, and total.

## Deploy it

Bring this folder to Tokay any way you like. Paste or upload it in the dashboard, push it with git, or hand it to your AI agent along with [our agent instructions](https://app.tokay.io/llms.txt). Tokay figures out the rest.

Working in Claude, ChatGPT, VS Code, or another MCP client? Connect the [Tokay MCP server](https://tokay.io/docs/platform-mcp) and ask your agent to deploy this example. It signs in through your browser, so there is no token to paste.

New to Tokay? The [getting started guide](https://tokay.io/getting-started) walks you through your first deploy.

## Try it

1. Change the client or line items and press **Create PDF invoice**.
2. Open the PDF and note its number, then deploy the app again.
3. Find that file under **Recent invoices** and create another. Its number continues the sequence.

## How it works

You keep control of the document design because the app builds an HTML invoice and WeasyPrint turns that exact markup into the PDF. Tokay includes the native Pango and Cairo libraries around your declared Python package.

SQLite locks the counter while a PDF is created, then records the number only after the file is safely in place. Tokay preserves and replicates both the database and invoice directory. Read [Files and persistent storage](https://tokay.io/docs/persistent-storage) for the protection model.

## Secrets

You do not need a secret. Invoice files and numbering stay in Tokay's persistent storage.

## Grow from here

Try the [receipt box](/examples/node-sqlite-uploads-receipt-box) when the app starts with an uploaded image instead of a generated PDF.

## Source files

- [main.py](https://tokay.io/examples/src/python-pdf-invoice-generator/main.py)
- [requirements.txt](https://tokay.io/examples/src/python-pdf-invoice-generator/requirements.txt)

## Download and source

- [Download the complete project](https://tokay.io/examples/downloads/python-pdf-invoice-generator.zip)
- Last updated: 2026-07-31
- Example revision: `52c7b7f`
- [View this revision on GitHub](https://github.com/tokayio/tokay-examples/tree/52c7b7ffd52e157375b08f1f11ff4fbe6c498642/python-pdf-invoice-generator)
- [Deploy an app that uses SQLite](https://tokay.io/use-cases/deploy-app-with-sqlite)
