What is PyAvaTax?

As of Sept 2012 US internet retailers are required to pay sales tax in all the states they do business. Avalara offers a fully featured web-based service to report your transactions, return your sales tax, and store all the information until you need to report it.

Avalara is a US-only service, and thus all amounts passing through their system, and this api, are assumed to be US Dollars (USD)

We developed PyAvaTax as a Python client library for easily integrating with Avalara’s RESTful AvaTax API Service to report your transactions.

PyAvaTax does not require Django, though if you are using a Django system we have some admin-based goodies for you to check out! If you’re running this on a system with Django installed (e.g. we can find Django in the import path) we will attempt to integrate with it. If you don’t want this default behavior, please see the Django section on how to prevent it.

AvaTax expects a JSON (or XML) POST to their tax/get/ URI, like this:

    "DocDate": "2012-10-24",
    "CompanyCode": "FooBar",
    "CustomerCode": "",
    "DocCode": "1001",
    "DocType": "SalesOrder",
            "AddressCode": "1",
            "Line1": "435 Ericksen Avenue Northeast",
            "Line2": "#250",
            "PostalCode": "98110"
            "AddressCode": "2",
            "Line1": "7562 Kearney St.",
            "PostalCode": "80022-1336"
            "LineNo": "1",
            "DestinationCode": "2",
            "OriginCode": "1",
            "Qty": 1,
            "Amount": "100"

Our library, accepts your data in a variety of ways. You instantiate the API like so


Then, you can perform an action (e.g. “Post Tax”), by passing in a data dictionary. We will parse it, validate it, handle the HTTP layer for you, and return a response object to you.

tax_response = api.post_tax(dictionary_data)
print tax_response.TotalTax  # this is unicode
>>> 0.86

That returned object will have all the response data from AvaTax easily accessible by dot-notation.

Or, you can use the library to construct objects from kwargs

doc = Document.new_sales_order(DocCode='1001',, CustomerCode='')
doc.add_from_address(Line1="435 Ericksen Avenue Northeast", Line2="#250", PostalCode="98110")
doc.add_to_address(Line1="7562 Kearney St.", PostalCode="80022-1336")
response = api.post_tax(doc)

We have a full-fledged introduction, from installation, logging, making requests, and handling responses, with a full example in the next topic: Basics

If you have any issues, improvements, requests, or bugs please use Github


Indices and tables