bubbleio.bubbleio module#
This module contans Bubbleio class to handle Bubble.io API.
https://manual.bubble.io/core-resources/api/data-api
- class bubbleio.bubbleio.Bubbleio(api_key, api_root)#
Bases:
object
Instantiate a Bubbleio object
- Parameters:
api_key (str) – Your Bubble.io API Key to the specific app. Don’t forget to enable API in yout Bubble app in Settings > API. You can also get an API token from there.
api_root (str) – The root URL of the API. Currently, the API root is generally https://appname.bubbleapps.io/api/1.1/obj. It can also depends if you have a custom domain name.
Returns – Bubbleio: Instance of Bubbleio.
Examples –
>>> from bubbleio import Bubbleio >>> API_KEY = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" >>> API_ROOT = "https://appname.bubbleapps.io/api/1.1/obj" >>> bbio = Bubbleio(API_KEY, API_ROOT)
- headers()#
Returns headers including authentication
Note : considering passing as private method.
Examples
>>> from bubbleio import Bubbleio >>> API_KEY = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" >>> API_ROOT = "https://appname.bubbleapps.io/api/1.1/obj" >>> bbio = Bubbleio(API_KEY, API_ROOT) >>> bbio.header() {'Authorization': 'Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'}
- get(typename, limit=None, cursor=None, constraints=None)#
Python implementation of Bubble.io GET API call.
Use this call to retrieve a list of things of a given type. By default, all GET requests return the first 100 items in the list, unless you a lesser limit argument.
- Parameters:
typename (str) – The type of “things” you are querying.
limit (str) – Use limit to specify the number of items you want in the response. The default and maximum allowed is 100. Use cursor to specify where to start.
cursor (str) – This is the rank of the first item in the list.
constraints (list) – See https://manual.bubble.io/core-resources/api/data-api#search-constraints. This parameter should be an list of constraints, e.g., objects with a
key
,constraint_type
, and most of the time avalue
.
- Returns:
Returns a decoded JSON (dict) as documented in Bubble.io API documentation. Items of the dict:
cursor
: This is the rank of the first item in the list,results
: The list of the results,count
: This is the number of items in the current response,remaining
: his is the number of remaining items after the current response. Use this for the next call
- Return type:
Dict
Examples
>>> from bubbleio import Bubbleio >>> API_KEY = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" >>> API_ROOT = "https://appname.bubbleapps.io/api/1.1/obj" >>> bbio = Bubbleio(API_KEY, API_ROOT) >>> bbio.get("fooType") { "cursor": 0, "results": [ { "foo_field_1": "value1", "foo_field_2": "value2", "_id": "item1_bubble_id" }, { "foo_field_1": "value3", "foo_field_2": "value4", "_id": "item2_bubble_id" }, ... ], "remaining": 0, "count": 31 }
>>> bbio.get("fooType", constraints=[ ... {"key": "foo_field_1", "value": "value1", "constraint_type":"equals"} ... ]) { "cursor": 0, "results": [ { "foo_field_1": "value1", "foo_field_2": "value2", "_id": "item1_bubble_id" } ], "remaining": 0, "count": 1 }
- get_results(typename, limit=None, cursor=None, constraints=None)#
Same as get() method, but returns only the results.
- Parameters:
typename (str) – The type of “things” you are querying.
limit (str) – Use limit to specify the number of items you want in the response. The default and maximum allowed is 100. Use cursor to specify where to start.
cursor (str) – This is the rank of the first item in the list.
constraints (list) – See https://manual.bubble.io/core-resources/api/data-api#search-constraints. This parameter should be an list of constraints, e.g., objects with a
key
,constraint_type
, and most of the time avalue
. Seeget()
example.
- Returns:
The list of all items of the type.
- Return type:
List
Examples
>>> from bubbleio import Bubbleio >>> API_KEY = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" >>> API_ROOT = "https://appname.bubbleapps.io/api/1.1/obj" >>> bbio = Bubbleio(API_KEY, API_ROOT) >>> bbio.get_results("fooType") [ { "foo_field_1": "value", "foo_field_2": "value", "_id": "item1_bubble_id" }, { "foo_field_1": "value", "foo_field_2": "value", "_id": "item2_bubble_id" }, ... ]
- get_all_results(typename, constraints=None, progress_callback=None, progress_callback_resolution=0.1)#
Get all intems of one “things” type. The function iterates with limit and cursor to get all items
- Parameters:
typename (str) – The type of “things” you are querying.
constraints (list) – See https://manual.bubble.io/core-resources/api/data-api#search-constraints. This parameter should be an list of constraints, e.g., objects with a
key
,constraint_type
, and most of the time avalue
. Seeget()
example.progress_callback – Function to be called to communicate progress
progress_callback_resolution – Parameter user to tune the frequency of callback_progress function.
- Returns:
The list of all items of the type.
- Return type:
List
- get_results_as_df(typename, limit=None, cursor=None, constraints=None)#
Returns results as a Pandas.DataFrame
- Parameters:
typename (str) – The type of “things” you are querying.
limit (str) – Use limit to specify the number of items you want in the response. The default and maximum allowed is 100. Use cursor to specify where to start.
cursor (str) – This is the rank of the first item in the list.
constraints (list) – See https://manual.bubble.io/core-resources/api/data-api#search-constraints. This parameter should be an list of constraints, e.g., objects with a
key
,constraint_type
, and most of the time avalue
. Seeget()
example.progress_callback – Function to be called to communicate progress
progress_callback_resolution – Parameter user to tune the frequency of callback_progress function.
- Returns:
The list of all items of the type.
- Return type:
Pandas.DataFrame
Examples
>>> from bubbleio import Bubbleio >>> bbio = Bubbleio(API_KEY, API_ROOT) >>> bbio.get_results("fooType") _id fooField1 fooField2 fooBar idFoo1 value value idBar1 idFoo2 value value idBar2
- get_all_results_as_df(typename, joins=None, constraints=None, progress_callback=None, progress_callback_resolution=0.1)#
Returns all results as a Pandas.DataFrame
- Parameters:
typename (str) – The type of “things” you are querying..
joins (list) –
List of dicts giving the parameters of the joins to be made. Dict must have these Items :
field: Name of the field referencing the foreign table (foreign key)
typename: Name of the foreign table to be joined
constraints (list) – See https://manual.bubble.io/core-resources/api/data-api#search-constraints. This parameter should be an list of constraints, e.g., objects with a
key
,constraint_type
, and most of the time avalue
. Seeget()
example.
- Returns:
The list of all items of the type.
- Return type:
Pandas.DataFrame
Examples
>>> from bubbleio import Bubbleio >>> bbio = Bubbleio(API_KEY, API_ROOT) >>> joins_ = [ ... { ... "field": "fooBar", ... "typename": "barType", ... } ... ] >>> bbio.get_results("fooType") _id fooField1 fooField2 fooBar idFoo1 value value idBar1 idFoo2 value value idBar2 >>> bbio.get_results("barType") _id barField1 barField2 idBar1 value value idBar2 value value >>> bbio.get_all_results_as_df("fooType", joins=joins_) _id fooField1 fooField2 fooBar fooBar__id fooBar_barField1 fooBar_barField2 idFoo1 value value idBar1 idBar1 value value idFoo2 value value idBar2 idBar2 value value
- patch(typename, unique_id, values, ignore_errors=False)#
Python implementaiton of PATCH API call
To modify a thing, send a PATCH request to the same endpoint you use to retrieve it. The body of the request should be a JSON object with a list of keys and values to modify.