Skip to main content

A client library for the FreshBooks API

Project description

Refreshbooks provides a simple synchronous API for manipulating FreshBooks
invoices, clients, and other data::

from refreshbooks import api

c = api.OAuthClient(
'My Consumer Secret',
'An existing token',
'An existing token secret',

# XML structure inferred from args
response = c.invoice.create( # <request method="invoice.create">
invoice=dict( # <invoice>
client_id='8', # <client_id>8</client_id>
lines=[ # <lines>
api.types.line( # <line>
name='Yard Work', # <name>Yard Work</name>
unit_cost='10', # <unit_cost>10</unit_cost>
quantity='4' # <quantity>4</quantity>
) # </line>
] # </lines>
) # </invoice>
) # </request>

invoice_response = c.invoice.get( # <request method="invoice.get">
invoice_id=response.invoice_id # <invoice_id>...</invoice_id>
) # </request>

print "New invoice created: #%s (id %s)" % (

invoices_response = c.invoice.list() # <request method="invoice.list" />

print "There are %s pages of invoices." % (

for invoice in invoices_response.invoices.invoice:
print "Invoice %s total: %s" % (

Consumer keys and secrets can be obtained from FreshBooks. This library
does not handle negotiating for an OAuth token+secret pair; see the
`oauth` module or the OAuth specification for details.

This library also supports the older token-based API authorization

c = api.TokenClient(
'My API token',

# ... as above ...

API methods return lxml.objectify.ObjectifiedDataElement trees, which
can be manipulated as Python objects with the same structure as the
underlying XML.

If you are having trouble accessing items as in:

items_response = c.items.list()
for item in items_response.items.item:
print item.item_id

Adjust your syntax to use dictionary item lookup:

items_response = c.items.list()
for item in items_response['items'].item:
print item.item_id

ObjectifiedDataElement provides a method named items which shadows the
items element in the response. Accessing items with dictionary lookup
syntax is the known work-around.

To run tests:

python nosetests

To run network-accessing integration tests against

python nosetests --attr=integration


- - The FreshBooks API
- - FreshBooks and OAuth

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

refreshbooks-1.7.1.tar.gz (13.1 kB view hashes)

Uploaded Source

Built Distributions

refreshbooks-1.7.1-py2.7.egg (21.2 kB view hashes)

Uploaded Source

refreshbooks-1.7.1-py2.6.egg (21.2 kB view hashes)

Uploaded Source

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