{"id":7645,"library":"pyxero","title":"PyXero","description":"PyXero is a community-maintained Python library for accessing the Xero accounting software's REST API. It provides a convenient object-oriented interface to interact with various Xero entities like contacts, invoices, and accounts. The library is actively maintained with irregular but consistent releases, primarily focusing on supporting Xero's evolving API and compatible Python versions.","status":"active","version":"0.9.5","language":"en","source_language":"en","source_url":"https://github.com/freakboy3742/pyxero","tags":["xero","accounting","api","oauth","client-library"],"install":[{"cmd":"pip install pyxero","lang":"bash","label":"Install PyXero"}],"dependencies":[{"reason":"Required for OAuth2 authentication flows.","package":"requests-oauthlib","optional":false},{"reason":"Used for OAuth1 authentication (deprecated by Xero).","package":"rsa","optional":true},{"reason":"Used for OAuth1 authentication (deprecated by Xero).","package":"cryptography","optional":true}],"imports":[{"note":"The PyPI package name is `pyxero`, but the top-level Python import module is `xero`.","wrong":"from pyxero import Xero","symbol":"Xero","correct":"from xero import Xero"},{"note":"The PyPI package name is `pyxero`, but the top-level Python import module is `xero`.","wrong":"from pyxero.oauth2 import XeroOAuth2","symbol":"XeroOAuth2","correct":"from xero.oauth2 import XeroOAuth2"}],"quickstart":{"code":"import os\nfrom xero import Xero\n\n# Set these environment variables with your Xero OAuth2 credentials:\n# XERO_ACCESS_TOKEN: Your active Xero OAuth2 access token.\n# XERO_TENANT_ID: The Xero organization (tenant) ID you want to connect to.\n# To obtain these, you must first complete the Xero OAuth2 authorization flow\n# (involving redirecting a user to Xero for consent and obtaining tokens).\naccess_token = os.environ.get('XERO_ACCESS_TOKEN', '')\ntenant_id = os.environ.get('XERO_TENANT_ID', '')\n\nif not access_token:\n    print(\"Error: Please set the XERO_ACCESS_TOKEN environment variable.\")\n    print(\"Refer to pyxero documentation for OAuth2 authorization flow details.\")\n    exit(1)\nif not tenant_id:\n    print(\"Error: Please set the XERO_TENANT_ID environment variable.\")\n    print(\"You can find the tenant ID after completing the OAuth2 authorization.\")\n    exit(1)\n\ntry:\n    xero = Xero(tenant_id, access_token)\n\n    # Example: Fetch the first 5 contacts\n    contacts = xero.contacts.all()\n    print(f\"Successfully fetched {len(contacts)} contacts. Displaying first 5:\")\n    for i, contact in enumerate(contacts):\n        if i >= 5:\n            break\n        print(f\"- {contact.Name} (ID: {contact.ContactID})\")\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\n    print(\"Please ensure your XERO_ACCESS_TOKEN and XERO_TENANT_ID are valid and have the necessary permissions.\")\n","lang":"python","description":"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."},"warnings":[{"fix":"Upgrade your Python environment to 3.9 or higher to use `pyxero` v0.9.5 and later.","message":"Python 3.8 support was dropped in `v0.9.5`, making Python 3.9+ the minimum requirement. Earlier versions (v0.9.4) dropped Python 3.7, and (v0.9.2) dropped 2.7/3.4.","severity":"breaking","affected_versions":">=0.9.5"},{"fix":"Migrate your application to use Xero's OAuth2 authorization flow and `xero.oauth2.XeroOAuth2`.","message":"Support for OAuth1 Private Applications was entirely removed in `v0.9.3`. PyXero now primarily supports OAuth2, aligning with Xero's own API deprecation roadmap for OAuth1.","severity":"breaking","affected_versions":">=0.9.3"},{"fix":"Always use `from xero import Xero` (or other submodules like `from xero.oauth2 import XeroOAuth2`) after installing `pyxero`.","message":"The PyPI package name is `pyxero`, but the actual Python import statement uses `from xero import ...`. This is a common source of `ModuleNotFoundError` if you attempt to import `pyxero` directly.","severity":"gotcha","affected_versions":"All"},{"fix":"Ensure your `Xero` client instance is consistently initialized with the correct `tenant_id` for all API calls, especially when interacting with the Files API.","message":"As of `v0.9.5`, usage of the Files API now explicitly includes the `tenant-id` in requests. While `pyxero` handles this if the `Xero` client is initialized correctly, older code that bypasses the client or doesn't pass a tenant_id might break.","severity":"breaking","affected_versions":">=0.9.5"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Ensure you have installed `pip install pyxero` and are importing with `from xero import ...` (note the `xero` module name, not `pyxero`).","cause":"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.","error":"ModuleNotFoundError: No module named 'xero'"},{"fix":"Obtain 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.","cause":"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.","error":"xero.exceptions.XeroException: Unauthorized (HTTP 401)"},{"fix":"Upgrade your Python environment to 3.9 or higher (the current minimum for `pyxero` v0.9.5).","cause":"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+).","error":"This Python version (X.X.X) is not supported"},{"fix":"Migrate your authentication logic to use `xero.oauth2.XeroOAuth2` and the OAuth2 authorization flow, as OAuth1 Private Apps are no longer supported.","cause":"You are attempting to use the `PrivateApplication` class or related methods which were entirely removed from `pyxero` in `v0.9.3`.","error":"AttributeError: 'Xero' object has no attribute 'private_application'"}]}