Install & Compatibility
Where this runs
tested against v0.9.5 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.896s · 40.8MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 3.3s · import 0.790s · 41MB
39MB installed
● package 39MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Xero
✓ from xero import Xero
✗ from pyxero import Xero
The PyPI package name is `pyxero`, but the top-level Python import module is `xero`.
XeroOAuth2
✓ from xero.oauth2 import XeroOAuth2
✗ from pyxero.oauth2 import XeroOAuth2
The PyPI package name is `pyxero`, but the top-level Python import module is `xero`.
This quickstart demonstrates how to initialize the PyXero client and fetch data using a pre-obtained OAuth2 access token and tenant ID. For initial authentication and token management (obtaining the access token and handling refreshes), refer to the official PyXero GitHub documentation on OAuth2 setup, which typically involves a web application flow to get the initial tokens.
import os
from xero import Xero
# Set these environment variables with your Xero OAuth2 credentials:
# XERO_ACCESS_TOKEN: Your active Xero OAuth2 access token.
# XERO_TENANT_ID: The Xero organization (tenant) ID you want to connect to.
# To obtain these, you must first complete the Xero OAuth2 authorization flow
# (involving redirecting a user to Xero for consent and obtaining tokens).
access_token = os.environ.get('XERO_ACCESS_TOKEN', '')
tenant_id = os.environ.get('XERO_TENANT_ID', '')
if not access_token:
print("Error: Please set the XERO_ACCESS_TOKEN environment variable.")
print("Refer to pyxero documentation for OAuth2 authorization flow details.")
exit(1)
if not tenant_id:
print("Error: Please set the XERO_TENANT_ID environment variable.")
print("You can find the tenant ID after completing the OAuth2 authorization.")
exit(1)
try:
xero = Xero(tenant_id, access_token)
# Example: Fetch the first 5 contacts
contacts = xero.contacts.all()
print(f"Successfully fetched {len(contacts)} contacts. Displaying first 5:")
for i, contact in enumerate(contacts):
if i >= 5:
break
print(f"- {contact.Name} (ID: {contact.ContactID})")
except Exception as e:
print(f"An error occurred: {e}")
print("Please ensure your XERO_ACCESS_TOKEN and XERO_TENANT_ID are valid and have the necessary permissions.")
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'xero'
You installed the `pyxero` package but are trying to import it using an incorrect name (e.g., `import pyxero`) or it's not installed correctly.
fixEnsure you have installed `pip install pyxero` and are importing with `from xero import ...` (note the `xero` module name, not `pyxero`).
xero.exceptions.XeroException: Unauthorized (HTTP 401)
Your OAuth2 access token is either invalid, expired, or does not have the necessary scopes. Alternatively, the `tenant_id` might be incorrect or you lack access to it.
fixObtain a fresh access token through the OAuth2 flow, ensure it has the required scopes, and verify your `XERO_TENANT_ID` is correct and accessible to the provided token.
This Python version (X.X.X) is not supported
You are running a version of Python that is no longer supported by your `pyxero` version (e.g., Python 3.8 or older for `pyxero` v0.9.5+).
fixUpgrade your Python environment to 3.9 or higher (the current minimum for `pyxero` v0.9.5).
AttributeError: 'Xero' object has no attribute 'private_application'
You are attempting to use the `PrivateApplication` class or related methods which were entirely removed from `pyxero` in `v0.9.3`.
fixMigrate your authentication logic to use `xero.oauth2.XeroOAuth2` and the OAuth2 authorization flow, as OAuth1 Private Apps are no longer supported.
Upgrade
Version history
0.9.5latest on PyPI · released Jun 4, 2025
Audit
Dependencies
requests-oauthlibrequiredRequired for OAuth2 authentication flows.
rsaoptionalUsed for OAuth1 authentication (deprecated by Xero).
cryptographyoptionalUsed for OAuth1 authentication (deprecated by Xero).