Welcome to Bexio API Python Client’s documentation!¶
Contents:
Bexio API Python Client¶
Bexio API Python Client. It works as a standalone lib in python, but needs additional work to get it started. There is a Django integration, that works out of the box, once you set it up properly as described later. If you wish to use it with Python alone, you can take a look at the Django integration. It shows how you can use it with python alone.
Features¶
- API connection to your Bexio instance
- Django integration
- Creation & Auto-renewal of access token
Documentation¶
The full documentation is at https://bexio-api-python-client.readthedocs.io.
Quickstart¶
Install Bexio API Python Client:
pip install bexio-api-python-client
If you are using anything other than Django with this module, you need to write some more code to authenticate and use the API. Check out the Django parts of the module to see how it can be done.
Django Integration¶
You can use the API directly with Django. There are URLs, Views and other helpers to integrate the API into your Django project.
Add it to your INSTALLED_APPS
:
INSTALLED_APPS = (
...
'bexiopy.apps.BexiopyConfig',
...
)
Add Bexio API Python Client’s URL patterns to your main urls.py
:
from bexiopy import urls as bexiopy_urls
urlpatterns = [
...
url(r'bexiopy/', include('bexiopy.urls', namespace='bexiopy')),
...
]
Start your server and visit the homepage (e.g. localhost:8000
).
You should see a navigation bar at the top where you can click on “Authenticate”
to create your token. Afterwards, you should see some data on the front page,
if you have any data in your Bexio instance.
Docker¶
If you use docker, you can configure a volume to store the token:
Example:
# docker-compose.yml
volumes:
bexio_token: {}
services:
app:
volumes:
- bexio_token:/app/secrets
# app/Dockerfile
...
RUN mkdir /app/secrets
...
Basic Usage¶
See docs for basic usage: https://bexio-api-python-client.readthedocs.io/en/latest/bexiopy.html#bexiopy.api.Client
You can also use helper functions, so you don’t need to create the call
every time (see docs).
These helper functions are added over time, but you can use the API fully, with the
call function. The helper methods only offer nicer ways to query the API (e.g. Bexiopy().contacts.get(2)
).
The progress of the helper functions are documented below under “Progress”.
Settings¶
Configure the minimum settings.py
(check docs for all options):
BEXIO_CLIENT_SECRET = 'my_secret'
BEXIO_CLIENT_ID = 'my_id'
BEXIO_APPLICATION_SCOPES = ['my_scope_1', 'my_scope_2']
BEXIO_APPLICATION_REDIRECTION_URL = 'https://example.com'
Start the server and go to /bexiopy/auth/
and authenticate with Bexio.
i18n URLs
If you have internationalized URLs, then make sure you place the Bexiopy
url outside the internationalized ones, so it can be called without any
language code (/bexiopy/auth/
instead of /en/bexiopy/auth/
).
Running Tests¶
Does the code actually work?
source <YOURVIRTUALENV>/bin/activate
(myenv) $ pip install tox
(myenv) $ tox
Credits¶
Tools and libs used in creating this package:
Progress¶
[ ] = Open
[~] = In Progress
[X] = Done
[-] = Not possible / Ignored
Contacts¶
Contacts¶
- [X] List contacts
- [X] Search contacts
- [X] Show contact
- [X] Create contact
- [X] Overwrite contact
- [X] Edit contact
- [X] Delete contact
- [ ] Bulk create contact
Salutations¶
- [ ] List salutations
- [ ] Search salutations
- [ ] Show salutation
- [ ] Create salutation
- [ ] Overwrite salutation
- [ ] Edit salutation
- [ ] Delete salutation
Titles¶
- [ ] List titles
- [ ] Search titles
- [ ] Show title
- [ ] Create title
- [ ] Overwrite title
- [ ] Edit title
- [ ] Delete title
Invoices¶
- [X] List invoices
- [X] Search invoices
- [X] Show invoice
- [X] Create invoice
- [X] Overwrite invoice
- [X] Edit invoice
- [X] Delete invoice
- [X] Show invoice pdf
- [X] Copy invoice
- [ ] Issue invoice
- [ ] Mark invoice as sent
- [ ] Send invoice
- [ ] List comments
- [ ] Search comments
- [ ] Show comment
- [ ] Create comment
- [-] List payments
- [-] Show payments
- [-] Create payments
- [-] Delete payments
Sponsorship¶
This project is maintained by Mathison AG | Mobile & Web Development.
Package¶
API¶
Settings¶
-
bexiopy.settings.
get_setting
(name)[source]¶ Receive a name and try to return the corresponding setting.
Parameters: name (str) – name of setting Returns: value of requested setting Return type: mixed Django
The settings defined in the root settings of your django project have priority over defaults.
Python
If you use the API without Django, you can define the settings in this file. Just add the following to the top of the file with your settings:
settings = { 'BEXIO_AUTH_URL': '...', 'BEXIO_CLIENT_ID': '...', 'BEXIO_CLIENT_SECRET': '...', ... }
Django Views¶
Resources¶
Base¶
-
class
bexiopy.resources.base.
BaseClientResource
[source]¶ Bases:
object
Base client resource that instantiates the
Client
.-
client
¶
-
-
class
bexiopy.resources.base.
BaseResource
(*args, **kwargs)[source]¶ Bases:
bexiopy.resources.base.BaseClientResource
Base resource that’s inherited by all other resources.
Inheriting classes may have additional methods, that are resource specific. Take a look at the resources to find these additional methods.
-
ENDPOINT
¶ the endpoint that should be queried
Type: str
-
ENDPOINT_SEARCH
¶ the serach endpoint that should be queried
Type: str
-
all
()[source]¶ Get all objects of given endpoint.
Returns: List of all objects from requested endpoint. Return type: list
-
create
(data)[source]¶ Add new object.
Parameters: data ( dict
) – Dictionary object with appropriate data.Returns: Object that has been created. Return type: dict
-
delete
(pk)[source]¶ Delete object.
Parameters: pk (str) – Bexio id of object. Returns: Response dictionary of operation. Return type: dict
-
get
(pk)[source]¶ Get specific object.
Parameters: pk (str) – Bexio id of object. Returns: Object that has been pulled. Return type: dict
-
get_or_create
(pk=None, data={})[source]¶ Return object if exists, else create object first.
Parameters: - pk (str) – Bexio id of object.
- data (dict) – Data for possible object creation.
Returns: Object that has been pulled.
Return type: dict
-
overwrite
(pk, data)[source]¶ Add new contact
Parameters: - pk (str) – Bexio id of object.
- data (dict) – Data that should be overwritten.
Returns: Object that has been overwritten.
Return type: dict
-
search
(params=[])[source]¶ Search for specific object and return response.
Parameters: params ( list
ofdict
, optional) – Parameters to narrow down the search.Returns: List of results from request. Return type: list
-
Contacts¶
-
class
bexiopy.resources.contacts.
ContactsResource
(*args, **kwargs)[source]¶ Bases:
bexiopy.resources.base.BaseResource
Resource to query the contacts endpoint.
Endpoint Docs:
Examples:
bexio = Bexiopy() # get all contacts contacts = bexio.contacts.all() # create an invoice contact = bexio.invoices.create(params={'attr1': 'val1', ...) # search a contact contact = bexio.contacts.search(params={'param1': 'some value'}) # get one specific contact with id 2 contact = bexio.contacts.get(pk=2)
-
ENDPOINT
= 'contact'¶
-
ENDPOINT_SEARCH
= 'contact/search'¶
-
General¶
Invoices¶
-
class
bexiopy.resources.invoices.
InvoicesResource
(*args, **kwargs)[source]¶ Bases:
bexiopy.resources.base.BaseResource
Resource to query the contacts endpoint.
Endpoint Docs:
Examples:
from bexiopy.api import * api = Bexiopy() # create invoice invoice = api.invoices.create(invoice_data) # get an invoice invoice = api.invoices.get(23) # update invoice invoice = api.invoices.update(23, { 'user_id': 1, 'contact_id': 2, 'header': 'New Header' } ) # delete invoice invoice = api.invoices.delete(23) # search for invoices api.invoices.search( [ {'field': 'user_id', 'value': 1}, {'field': 'contact_id', 'value': 2} ] )
-
ENDPOINT
= 'kb_invoice'¶
-
ENDPOINT_SEARCH
= 'kb_invoice/search'¶
-
Contributing¶
Contributions are welcome, and they are greatly appreciated! Every little bit helps, and credit will always be given.
You can contribute in many ways:
Types of Contributions¶
Report Bugs¶
Report bugs at https://github.com/oesah/bexio-api-python-client/issues.
If you are reporting a bug, please include:
- Your operating system name and version.
- Any details about your local setup that might be helpful in troubleshooting.
- Detailed steps to reproduce the bug.
Fix Bugs¶
Look through the GitHub issues for bugs. Anything tagged with “bug” is open to whoever wants to implement it.
Implement Features¶
Look through the GitHub issues for features. Anything tagged with “feature” is open to whoever wants to implement it.
Write Documentation¶
Bexio API Python Client could always use more documentation, whether as part of the official Bexio API Python Client docs, in docstrings, or even on the web in blog posts, articles, and such.
Submit Feedback¶
The best way to send feedback is to file an issue at https://github.com/oesah/bexio-api-python-client/issues.
If you are proposing a feature:
- Explain in detail how it would work.
- Keep the scope as narrow as possible, to make it easier to implement.
- Remember that this is a volunteer-driven project, and that contributions are welcome :)
Get Started!¶
Ready to contribute? Here’s how to set up bexio-api-python-client for local development.
Fork the bexio-api-python-client repo on GitHub.
Clone your fork locally:
$ git clone git@github.com:your_name_here/bexio-api-python-client.git
Install your local copy into a virtualenv. Assuming you have virtualenvwrapper installed, this is how you set up your fork for local development:
$ mkvirtualenv bexio-api-python-client $ cd bexio-api-python-client/ $ python setup.py develop
Create a branch for local development:
$ git checkout -b name-of-your-bugfix-or-feature
Now you can make your changes locally.
When you’re done making changes, check that your changes pass flake8 and the tests, including testing other Python versions with tox:
$ flake8 bexiopy tests $ python setup.py test $ tox
To get flake8 and tox, just pip install them into your virtualenv.
Commit your changes and push your branch to GitHub:
$ git add . $ git commit -m "Your detailed description of your changes." $ git push origin name-of-your-bugfix-or-feature
Submit a pull request through the GitHub website.
Pull Request Guidelines¶
Before you submit a pull request, check that it meets these guidelines:
- The pull request should include tests.
- If the pull request adds functionality, the docs should be updated. Put your new functionality into a function with a docstring, and add the feature to the list in README.rst.
- The pull request should work for Python 2.6, 2.7, and 3.3, and for PyPy. Check https://travis-ci.org/oesah/bexio-api-python-client/pull_requests and make sure that the tests pass for all supported Python versions.
Credits¶
Development Lead¶
- Özer Sahin <o.sahin@oesah.de>
Contributors¶
None yet. Why not be the first?