|
| 1 | +MessageBird's REST API for Python |
| 2 | +================================= |
| 3 | +This repository contains the open source Python client for MessageBird's REST API. Documentation can be found at: https://www.messagebird.com/developers/python. |
| 4 | + |
| 5 | +Requirements |
| 6 | +------------ |
| 7 | +- [Sign up](https://www.messagebird.com/en/signup) for a free MessageBird account |
| 8 | +- Create a new access key in the developers sections |
| 9 | +- An application written in Python (tested with Python 2.7 and Python 3.4) |
| 10 | + |
| 11 | +Installation |
| 12 | +------------ |
| 13 | +The easiest way to use the MessageBird API in your Python project is to install it using the setup.py file: |
| 14 | + |
| 15 | +``` |
| 16 | +$ sudo python setup.py install |
| 17 | +``` |
| 18 | + |
| 19 | +Examples |
| 20 | +-------- |
| 21 | +We have put some self-explanatory examples in the [examples](https://github.com/messagebird/python-rest-api/tree/master/examples) directory, but here is a quick example on how to get started. Assuming the installation was successful, you can import the messagebird package like this: |
| 22 | + |
| 23 | +```python |
| 24 | +import messagebird |
| 25 | +``` |
| 26 | + |
| 27 | +Then, create an instance of **messagebird.Client**: |
| 28 | + |
| 29 | +```python |
| 30 | +client = messagebird.Client('test_gshuPaZoeEG6ovbc8M79w0QyM') |
| 31 | +``` |
| 32 | + |
| 33 | +Now you can query the API for information or send a request. For example, if we want to request our balance information you'd do something like this: |
| 34 | + |
| 35 | +```python |
| 36 | +try: |
| 37 | + # Fetch the Balance object. |
| 38 | + balance = client.balance() |
| 39 | + |
| 40 | + # Print the object information. |
| 41 | + print('\nThe following information was returned as a Balance object:\n') |
| 42 | + print(' amount : %d' % balance.amount) |
| 43 | + print(' type : %s' % balance.type) |
| 44 | + print(' payment : %s\n' % balance.payment) |
| 45 | + |
| 46 | +except messagebird.client.ErrorException as e: |
| 47 | + print('\nAn error occured while requesting a Balance object:\n') |
| 48 | + |
| 49 | + for error in e.errors: |
| 50 | + print(' code : %d' % error.code) |
| 51 | + print(' description : %s' % error.description) |
| 52 | + print(' parameter : %s\n' % error.parameter) |
| 53 | + |
| 54 | +``` |
| 55 | + |
| 56 | +This will give you something like: |
| 57 | +```shell |
| 58 | +$ python example.py |
| 59 | + |
| 60 | + amount : 9 |
| 61 | + type : credits |
| 62 | + payment : prepaid |
| 63 | +``` |
| 64 | + |
| 65 | +Please see the other examples for a complete overview of all the available API calls. |
| 66 | + |
| 67 | +Documentation |
| 68 | +------------- |
| 69 | +Complete documentation, instructions, and examples are available at: |
| 70 | +[https://www.messagebird.com/developers/python](https://www.messagebird.com/developers/python). |
| 71 | + |
| 72 | +License |
| 73 | +------- |
| 74 | +The MessageBird REST Client for Python is licensed under [The BSD 2-Clause License](http://opensource.org/licenses/BSD-2-Clause). Copyright (c) 2014, MessageBird |
0 commit comments