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 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.8.0.tar.gz (8.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

xerosdk-0.8.0-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: xerosdk-0.8.0.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

File hashes

Hashes for xerosdk-0.8.0.tar.gz
Algorithm Hash digest
SHA256 fd78e52954b9187e5a0a9dafc7aabcb05713f4754f7973c33456a7aa481701df
MD5 a4614132f8564edf9f3306e6fa641100
BLAKE2b-256 798181ee69e471c994c5ac30374f5da5fb79d92b580156ecde8ee858d9133051

See more details on using hashes here.

File details

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

File metadata

  • Download URL: xerosdk-0.8.0-py3-none-any.whl
  • Upload date:
  • Size: 13.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

File hashes

Hashes for xerosdk-0.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4205635ddd96038318fb38749174ca36692bd9315ff9de24701f1f0c6a09996f
MD5 9a2c562fd22030de19137ae9a3a321b6
BLAKE2b-256 f55562a94e3acdf2d288b50539fd91223ae83aa118979d14e80d2231bddce2e5

See more details on using hashes here.

Supported by

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