QuickBooks Online API Client
python-quickbooks is an actively maintained Python 3 library designed for interacting with the QuickBooks Online API. It provides a convenient object-oriented interface to access and manage QuickBooks data, abstracting away the complexities of the REST API and OAuth 2.0 authentication. The library integrates with `intuit-oauth` for secure authentication. Releases appear on an as-needed basis, with multiple updates throughout the year.
Warnings
- breaking QuickBooks Online API minor versions 1-74 are being deprecated by Intuit starting August 1, 2025. If your application relies on specific behaviors or schemas from these older minor versions, it may break. The `python-quickbooks` library defaults the minor version to the minimum supported version (currently 75 in 0.9.12) which may change behavior for applications not explicitly setting a `minorversion` parameter.
- breaking Python 2 support has been completely removed from the library. Attempts to use it in a Python 2 environment will result in errors related to syntax, decorators, and removed dependencies.
- deprecated The `simplejson` dependency was removed. If your application directly imported `simplejson` via an internal `python-quickbooks` path, those imports will now fail.
- gotcha OAuth 2.0 access tokens have a limited lifespan (typically 1 hour) and require a refresh token to obtain new access tokens. Failure to correctly manage and refresh tokens will lead to `401 Unauthorized` or `400 invalid_grant` errors.
- gotcha Queries for objects (e.g., `Customer.all()`) have a default maximum return of 100 entities and an absolute maximum of 1000 entities per single API call. Fetching large datasets requires pagination.
- gotcha Directly passing unsanitized user input into QuickBooks Query Language (QBL) can lead to security vulnerabilities (e.g., SQL injection-like attacks).
Install
-
pip install python-quickbooks
Imports
- QuickBooks
from quickbooks import QuickBooks
- AuthClient
from intuitlib.client import AuthClient
- Customer
from quickbooks.objects.customer import Customer
Quickstart
import os
from intuitlib.client import AuthClient
from quickbooks import QuickBooks
from quickbooks.objects.customer import Customer
# Retrieve credentials from environment variables for security
CLIENT_ID = os.environ.get('QBO_CLIENT_ID', 'YOUR_CLIENT_ID')
CLIENT_SECRET = os.environ.get('QBO_CLIENT_SECRET', 'YOUR_CLIENT_SECRET')
REFRESH_TOKEN = os.environ.get('QBO_REFRESH_TOKEN', 'YOUR_REFRESH_TOKEN')
COMPANY_ID = os.environ.get('QBO_COMPANY_ID', 'YOUR_COMPANY_ID') # Also known as Realm ID
REDIRECT_URI = os.environ.get('QBO_REDIRECT_URI', 'http://localhost:8000/callback')
ENVIRONMENT = os.environ.get('QBO_ENVIRONMENT', 'sandbox') # 'sandbox' or 'production'
# Initialize AuthClient
auth_client = AuthClient(
CLIENT_ID,
CLIENT_SECRET,
REDIRECT_URI,
ENVIRONMENT
)
# Initialize QuickBooks client
qb = QuickBooks(
auth_client=auth_client,
refresh_token=REFRESH_TOKEN,
company_id=COMPANY_ID,
minorversion=75 # Recommended: use the latest supported minor version
)
try:
# Automatically refresh token if needed (handled by the library)
# Fetch all customers
customers = Customer.all(qb=qb, max_results=10) # Limit results for demonstration
for customer in customers:
print(f"Customer ID: {customer.Id}, Display Name: {customer.DisplayName}")
# Example: Create a new customer (uncomment to run)
# new_customer = Customer()
# new_customer.DisplayName = "New Test Customer"
# new_customer.CompanyName = "Test Company, Inc."
# new_customer.save(qb=qb)
# print(f"Created new customer: {new_customer.DisplayName} (ID: {new_customer.Id})")
except Exception as e:
print(f"An error occurred: {e}")
# Implement robust error handling and token refresh logic in production