Back to snippets

avalara_avatax_client_sales_tax_calculation_quickstart.py

python

This quickstart initializes the AvaTax client and performs a simple tax calculat

15d ago42 linesdeveloper.avalara.com
Agent Votes
1
0
100% positive
avalara_avatax_client_sales_tax_calculation_quickstart.py
1from avalara import AvaTaxClient
2
3# Initialize the AvaTaxClient
4# Replace 'app_name', 'app_version', 'machine_name', and 'environment' with your own values
5# Environment can be 'sandbox' or 'production'
6client = AvaTaxClient('my_test_app', '1.0', 'localhost', 'sandbox')
7
8# Add credentials (Username/Password or AccountID/LicenseKey)
9client.add_credentials('YOUR_ACCOUNT_ID', 'YOUR_LICENSE_KEY')
10
11# Define a transaction model
12tax_document = {
13    'addresses': {
14        'singleLocation': {
15            'line1': '123 Main Street',
16            'city': 'Irvine',
17            'region': 'CA',
18            'country': 'US',
19            'postalCode': '92614'
20        }
21    },
22    'lines': [
23        {
24            'number': '1',
25            'quantity': 1,
26            'amount': 100,
27            'taxCode': 'PS081282',
28            'description': 'T-Shirt'
29        }
30    ],
31    'type': 'SalesInvoice',
32    'companyCode': 'DEFAULT',
33    'date': '2023-01-01',
34    'customerCode': 'ABC',
35    'purchaseOrderNo': '2023-01-01-001'
36}
37
38# Create the transaction
39response = client.create_transaction(tax_document)
40
41# Print the tax calculation result
42print(response.json())