Turn HTML or Markdown into branded, production-ready PDFs from your Python backend. The python-anvil SDK handles authentication, rate limiting, and binary response handling out of the box.
def get_data():
return {
"title": "Example Invoice",
"data": [{
"label": "Name",
"content": "Sally Jones",
}, {
"content": "Lorem **ipsum** dolor sit _amet_, consectetur adipiscing elit, sed [do eiusmod](https://www.useanvil.com/docs) tempor incididunt ut labore et dolore magna aliqua. Ut placerat orci nulla pellentesque dignissim enim sit amet venenatis.\n\nMi eget mauris pharetra et ultrices neque ornare aenean.\n\n* Sagittis eu volutpat odio facilisis.\n\n* Erat nam at lectus urna.",
}, {
"table": {
"firstRowHeaders": True,
"rows": [
["Description", "Quantity", "Price"],
["4x Large Widgets", "4", "$40.00"],
["10x Medium Sized Widgets in dark blue", "10", "$100.00"],
["10x Small Widgets in white", "6", "$60.00"],
],
},
}],
}
def generate_markdown_pdf():
anvil = Anvil(api_key=API_KEY)
payload = get_data()
print("Making Markdown PDF generation request...")
res = anvil.generate_pdf(payload)
# Write the bytes to disk
with open(FILE_OUTPUT, "wb") as f:
f.write(res)
print("Finished!")The python-anvil package is MIT-licensed and maintained in the open on GitHub.
$ pip install python-anvilInstall the Anvil Document SDK plugin in Claude Code and Claude will scaffold the SDK into your codebase — discovery, planning, and production-ready code.
/plugin marketplace add anvilco/anvil-plugins
/plugin install anvil-document-sdk@anvil-pluginsNo API key setup needed. The plugin connects to your Anvil account with OAuth and logs you in automatically.
Use custom HTML and CSS to lay out a 100% pixel-perfect document. Typical response time under 250ms, with 99% of requests completing in under 3.3 seconds. Try the example below and see documentation when ready to generate your own.
<!-- Generate an invoice PDF. Full code: https://github.com/anvilco/html-pdf-invoice-template --> <div class="page-container"> Page <span class="page"></span> of <span class="pages"></span> </div> <div class="logo-container"> <img style="height: 18px" src="https://app.useanvil.com/img/email-logo-black.png" > </div> <table class="invoice-info-container"> <tr> <td rowspan="2" class="client-name"> Client Name </td> <td> Anvil Co </td> </tr> <tr> <td> 123 Main Street </td> </tr> <tr> <td> Invoice Date: <strong>May 24th, 2024</strong> </td> <td> San Francisco CA, 94103 </td> </tr> <tr> <td> Invoice No: <strong>12345</strong> </td> <td> hello@useanvil.com </td> </tr> </table> <table class="line-items-container"> <thead> <tr> <th class="heading-quantity">Qty</th> <th class="heading-description">Description</th> <th class="heading-price">Price</th> <th class="heading-subtotal">Subtotal</th> </tr> </thead> <tbody> <tr> <td>2</td> <td>Blue large widgets</td> <td class="right">$15.00</td> <td class="bold">$30.00</td> </tr> <tr> <td>4</td> <td>Green medium widgets</td> <td class="right">$10.00</td> <td class="bold">$40.00</td> </tr> <tr> <td>5</td> <td>Red small widgets with logo</td> <td class="right">$7.00</td> <td class="bold">$35.00</td> </tr> </tbody> </table> <table class="line-items-container has-bottom-border"> <thead> <tr> <th>Payment Info</th> <th>Due By</th> <th>Total Due</th> </tr> </thead> <tbody> <tr> <td class="payment-info"> <div> Account No: <strong>123567744</strong> </div> <div> Routing No: <strong>120000547</strong> </div> </td> <td class="large">May 30th, 2024</td> <td class="large total">$105.00</td> </tr> </tbody> </table> <div class="footer"> <div class="footer-info"> <span>hello@useanvil.com</span> | <span>555 444 6666</span> | <span>useanvil.com</span> </div> </div>