Translate Webforms into 10 different languages with 1 click.Learn more.
Anvil Logo
Products
Industries
Resources
Developers
Product News

Introducing the Anvil API Python library

Author headshot
By Allan Almazan

Learn about the new Python library and its features.

Back to all articles
Introducing the Anvil API Python library

The Anvil API is now supported on Python via our official client library. The library is available now on GitHub and as a package through PyPI via pip install python-anvil or your preferred package manager (i.e. pipenv, poetry).

As a company, we are heavily invested in the Javascript ecosystem; however, we also realize that making our platform more developer-friendly and accessible to other developers means increasing our official API library footprint. That’s why we’ve added Python to our client library as another step towards building a more developer-friendly Anvil. We hope this release gives developers an opportunity to enjoy all that Anvil has to offer.

Features of this initial release:

  • Keeping in line with current Javascript library, it includes:
  • A command-line interface (CLI)
    • Contains the above, giving you the ability to test out our features in the Python REPL.
    • The anvil command from this package also has a few additional useful commands that will help you as you build out your integration, such as getting a list of PDF templates (or casts) for use in the “fill-pdf” API endpoint, as well as getting field data from a specific PDF template. All of this can be done from the comfort of your text-based terminal.

Filling PDFs

Filling PDFs lets you fill PDF templates created on Anvil with a simple API call.

First, create a template on your Anvil dashboard.

Once uploaded, Anvil will attempt to find fields for you. You can also create your own fields and adjust any field types if you need something specific such as date formats.

When you finish editing fields, click over to the API Info tab. It shows everything you need to fill the template with the API, including an example payload to quickly get started.

With the data on the API Info page, you can now create your API call. The resulting response will be the PDF file:

from python_anvil.api import Anvil

anvil = Anvil(api_key="MY API KEY")
data = {
    "title": "IRS W-4",
    "font_size": 10,
    "data": {
        "someFieldName": "Example data",
        "aNumberField": 1234
    }
}
response = anvil.fill_pdf("template_id_here", data)

Generating PDFs

The Anvil API also allows you to generate new PDFs using provided JSON data. Useful for agreements, invoices, disclosures, or any other text-heavy documents.

from python_anvil.api import Anvil

anvil = Anvil(api_key="MY API KEY")
data = {
    "title": "Example Invoice",
    "font_size": 12,
    "data": [{
        "content": "Supports **markdown**",
    }, {
        "table": {
            "rows": [
                ["Description", "Quantity", "Price"],
                ["4x Large Widgets", "4", "$40.00"],
                ["10x Medium Sized Widgets in dark blue", "10", "$100.00"],
                ["6x Small Widgets in white", "6", "$60.00"],
            ]
        }
    }]
}

response = anvil.generate_pdf("template_id_here", data)

Creating Etch Signing Packets

The Anvil Etch E-sign API allows you to collect e-signatures from within your app. Send a signature packet including multiple PDFs, images, and other uploads to one or more signers. Templatize your common PDFs. Then, fill them with your user's information before sending out the signature packet.

This is one of the more complex methods in the API, so please take a look at the Python Anvil docs for a closer look on the process.

Command-line interface

The included CLI gives you quick access to the methods above, as well as some additional GraphQL queries that can help with getting certain data without having to open up your browser.

When running the anvil command by itself, you'll be shown a display of support commands. Each individual command also has additional help documentation on how to use the command.

# The CLI commands will use the environment variable "ANVIL_API_KEY" for all
# Anvil API requests.
$ ANVIL_API_KEY=MY_GENERATED_KEY anvil
Usage: anvil [OPTIONS] COMMAND [ARGS]...

Options:
  --debug / --no-debug
  --help                Show this message and exit.

Commands:
  cast                Fetch Cast data given a Cast eid.
  create-etch         Create an etch packet with a JSON file.
  current-user        Show details about your API user
  download-documents  Download etch documents
  fill-pdf            Fill PDF template with data
  generate-etch-url   Generate an etch url for a signer
  generate-pdf        Generate a PDF
  weld                Fetch weld info or list of welds

Lastly, if you’re developing something cool with PDFs and/or paperwork automation, we’d love to hear more from you! Let us know at developers@useanvil.com if you have any feedback. Also, if there are any suggestions on new features or issues you may encounter for this library, let us know on the Issue section of the GitHub repo page, and we’ll get back to you.

Sign up for a live demo

Request a 30-minute live demo today and we'll get in touch shortly. During the meeting our Sales team will help you find the right solution, including:
  • Simplifying data gathering
  • Streamlining document preparation
  • Requesting e-signatures
  • Building and scaling your business
Want to try Anvil first?Sign up for free
Want to try Anvil first?Sign up for free