Skip to main content

PyMYOB

PyPI version versions Downloads Test Lint

A Python API around the MYOB Business API (formerly AccountRight Live, and New Essentials).

Pre-getting started

Register for API Keys with MYOB. You'll find detailed instructions here.

Getting started

Install:

pip install pymyob

Create a PartnerCredentials instance and provide the Key, Secret and Redirect Uri as you've set up in MYOB, along with the data scopes your integration needs:

from myob.constants import AuthScope
from myob.credentials import PartnerCredentials

cred = PartnerCredentials(
    consumer_key=<Key>,
    consumer_secret=<Secret>,
    callback_uri=<Redirect Uri>,
    scopes=(
        AuthScope.COMPANY_FILE,
        AuthScope.GENERAL_LEDGER,
        AuthScope.CONTACTS_CUSTOMER,
        AuthScope.SALES,
    ),
)

MYOB grants access per data scope, so ask only for what you need: your users are shown each one on the consent screen, and are more likely to grant a short list. AuthScope enumerates all of them; AuthScope.COMPANY_FILE covers reading the business's own name and product version.

Cache cred.state somewhere. You'll use this to rebuild the PartnerCredentials instance later. This object includes a datetime object, so if your cache does not serialise datetime objects, you'll need to find an alternative, such as pickling and saving to a binary database column.

Redirect the user to cred.url. There, they will need to log in to MYOB and authorise partnership with your app1. Once they do, they'll be redirected to the Redirect Uri you supplied.

At the url they're redirected to, rebuild the PartnerCredentials then pick the verifier out of the request and use it to verify the credentials.

Alongside the verifier, MYOB hands back the businessId of the business the user consented to. Hand it to verify along with the verifier: it identifies the business for every subsequent call, and this redirect is the only place you're given it. cred.state carries it from there, so the credentials you save below are all you need to keep.

from myob.credentials import PartnerCredentials

def myob_authorisation_complete_view(request):
    verifier = request.GET.get('code', None)
    business_id = request.GET.get('businessId', None)
    if verifier:
        state = <cached_state_from_earlier>
        if state:
            cred = PartnerCredentials(**state)
            cred.verify(verifier, business_id)
            if cred.verified:
                messages.success(request, 'OAuth verification successful.')
            else:
                messages.error(request, 'OAuth verification failed: verifier invalid.')
        else:
            messages.error(request, 'OAuth verification failed: nothing to verify.')
    else:
        messages.error(request, 'OAuth verification failed: no verifier received.')

Save cred.state once more, but this time you want it in persistent storage. So plonk it somewhere in your database.

With your application partnered with MYOB, you can now create a Myob instance from the verified credentials, and get at your data. Every call is made against the business the credentials cover, so there's nothing further to pass in.

from myob import Myob
from myob.credentials import PartnerCredentials

cred = PartnerCredentials(**<persistently_saved_state_from_verified_credentials>)
myob = Myob(cred)

# Obtain the business's own details, such as its name and product version.
# (This is the only call here that needs `AuthScope.COMPANY_FILE`.)
business = myob.business()

# Obtain a list of customers (two ways to go about this).
customers = myob.contacts.all(Type='Customer')
customers = myob.contacts.customer()

# Obtain a list of sale invoices (two ways to go about this).
invoices = myob.invoices.all(InvoiceType='Item', orderby='Number desc')
invoices = myob.invoices.item(orderby='Number desc')

# Create an invoice.
myob.invoices.post_item(data=data)

# Obtain a specific invoice.
invoice = myob.invoices.get_item(uid=<invoice_uid>)

# Download PDF for a specific invoice.
invoice_pdf = myob.invoices.get_item(uid=<invoice_uid>, headers={'Accept': 'application/pdf'})

# Obtain a list of tax codes.
taxcodes = myob.general_ledger.taxcode()

# Obtain a list of inventory items.
inventory = myob.inventory.item()

# Use endswith, startswith, or substringof filters
search_text = 'Acme'
customers = myob.contacts.customer(raw_filter=f"substringof('{search_text}', CompanyName)")

If you don't know what you're looking for, the reprs of most objects (eg. myob, myob.invoices above) will yield info on what managers/methods are available. Each method corresponds to one API call to MYOB.

Note that not all endpoints are covered here yet; we've just been adding them on an as-needed basis. If there's a particular endpoint you'd like added, please feel free to throw it into the endpoints.py file and open up a PR. All contributions are welcome and will be reviewed promptly. :)

1: Your users can review their partner authorisations at https://secure.myob.com/. ↩

Metadata

Release files for pymyob 3.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for pymyob 3.0.0
File Interpreter ABI Platform
pymyob-3.0.0-py3-none-any.whl Python 3 none any Details

Release files / pymyob-3.0.0-py3-none-any.whl

Download URL pymyob-3.0.0-py3-none-any.whl
Size 13.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f49152bc478194dc3bd31d83cd8c3d66ce26647a0d3a268914aefdf7953ce315
BLAKE2b-256 checksum
How to use checksums
2c8e82e424123fd916a089698d80dfd75c7f2e7b268606e82e090e6b4132343e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Hatch/1.18.0 {"ci":null,"cpu":"arm64","distro":{"name":"macOS","version":"26.5.1"},"implementation":{"name":"CPython","version":"3.12.1"},"installer":{"name":"hatch","version":"1.18.0"},"openssl_version":"OpenSSL 3.0.12 24 Oct 2023","python":"3.12.1","system":{"name":"Darwin","release":"25.5.0"}} HTTPX2/2.12.0

Release history Release notifications | RSS feed

This release

3.0.0 This release

1 release file

2.0.0

1 release file

1.4.0

1 release file

1.3.0

1 release file

1.2.24

1 release file

1.2.23

1 release file

1.2.21

1 release file

1.2.20

1 release file

1.2.19

1 release file

1.2.18

1 release file

1.2.17

1 release file

1.2.16

1 release file

1.2.15

1 release file

1.2.14

1 release file

1.2.13

1 release file

1.2.12

1 release file

1.2.11

1 release file

1.2.10

1 release file

1.2.9

1 release file

1.2.8

1 release file

1.2.7

1 release file

1.2.6

1 release file

1.2.5

1 release file

1.2.4

1 release file

1.2.3

1 release file

1.2.2

1 release file

1.2.1

1 release file

1.2

1 release file

1.1.12

1 release file

1.1.11

1 release file

1.1.9

1 release file

1.1.8

1 release file

1.1.7

1 release file

1.1.6

1 release file

1.1.5

1 release file

1.1.4

1 release file

1.1.3

1 release file

1.1.2

1 release file

1.1.1

1 release file

1.1

1 release file

1.0

1 release file

0.4.5

1 release file

0.4.4

1 release file

0.4.3

1 release file

0.4.2

1 release file

0.4.1

1 release file

0.4

1 release file

0.3.2

1 release file

0.3.1

1 release file

0.3

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.2

1 release file

0.1.8

1 release file

0.1.7

1 release file

0.1.6

1 release file

0.1.5

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page