Skip to main content

Python SDK to access Xero APIs

Project description

xero-sdk-py

Python SDK to access Xero APIs

Requirements

  1. Python 3+
  2. Requests library

Installation

Install Xero SDK using pip as follows:

pip install xerosdk

Usage

This SDK requires OAuth2 authentication credentials such as client ID, client secret and refresh token.

  1. Create a connection using the XeroSDK class.
from xerosdk import XeroSDK 

connection = XeroSDK(
    base_url='<XERO_BASE_URL>',
    client_id='<YOUR CLIENT ID>',
    client_secret='<YOUR CLIENT SECRET>',
    refresh_token='<YOUR REFRESH TOKEN>'
)

# tenant_id is required to make a call to any API
tenant_id = connection.tenants.get_all()[0]['tenantId']
connection.set_tenant_id(tenant_id)
  1. Access any of the API classes
"""
USAGE: <XeroSDK INSTANCE>.<API_NAME>.<API_METHOD>(<PARAMETERS>)
"""

# Get a list of all Invoices
response = connection.invoices.get_all()

# Get a list of all Invoices using generator
for response in invoices.list_all_generator():
   print(response)

# Get an Invoice by id
response = connection.invoices.get_by_id(<invoice_id>)

NOTE: Only Tenants, Invoices, Accounts, Contacts, Items and TrackingCategories API classes are defined in this SDK.

Integration Tests

  1. Install pytest package using pip as follows:
pip install pytest
  1. Create a 'test_credentials.json' file at project root directory and enter Xero OAuth2 authentication credentials of your Xero app.
{
  "base_url": "<xero_base_url>",
  "client_id": "<client_id>",
  "client_secret": "<client_secret>",
  "refresh_token": "<refresh_token>"
}
  1. Run integration tests as follows:
python -m pytest tests/integration

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xerosdk-0.14.2.tar.gz (11.2 kB view details)

Uploaded Source

Built Distribution

xerosdk-0.14.2-py3-none-any.whl (16.9 kB view details)

Uploaded Python 3

File details

Details for the file xerosdk-0.14.2.tar.gz.

File metadata

  • Download URL: xerosdk-0.14.2.tar.gz
  • Upload date:
  • Size: 11.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for xerosdk-0.14.2.tar.gz
Algorithm Hash digest
SHA256 708a3e7af51ddbb21681ae98d7102850c28bc6cba091499311b9ef11601426eb
MD5 931314e5fabc7cddfcff640a873cfdff
BLAKE2b-256 fa953e62606b5364aa5179b4978653ba8c879626996ad553016bb88033061805

See more details on using hashes here.

File details

Details for the file xerosdk-0.14.2-py3-none-any.whl.

File metadata

  • Download URL: xerosdk-0.14.2-py3-none-any.whl
  • Upload date:
  • Size: 16.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for xerosdk-0.14.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9c7006e3058fe0924ca4190d7c88ada9b94f1c5559bad06e0886bc22bc7eb15a
MD5 ed18dcf70aedef337d00501e75665d4b
BLAKE2b-256 86f2b518b738626dd0110085f2d796a57db24681db9d8908d002b91919ba50e4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page