Welcome to Clappform’s API Wrapper¶
Clappform allows one to easily connect and interact with a Clappform B.V. API. There is no need to manually program HTTP requests to authenticate and consume the API. Many resources of the API are able to be created, read, updated and deleted. To start using Clappform with logging:
>>> import logging
>>> from clappform import Clappform
>>> import clappform.dataclasses as r
>>> logging.basicConfig()
>>> logging.getLogger().setLevel(logging.DEBUG)
>>> requests_log = logging.getLogger("urllib3")
>>> requests_log.setLevel(logging.DEBUG)
>>> requests_log.propagate = True
>>> c = Clappform("https://app.clappform.com", "j.doe@clappform.com", "S3cr3tP4ssw0rd!")
DEBUG:urllib3.util.retry:Converted retries value: 3 -> Retry(total=3, connect=None, read=None, redirect=None, status=None)
>>> apps = c.get_apps(r.App())
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): app.clappform.com:443
DEBUG:urllib3.connectionpool:https://app.clappform.com:443 "POST /api/auth HTTP/1.1" 200 1912
DEBUG:urllib3.connectionpool:https://app.clappform.com:443 "GET /api/apps?extended=false HTTP/1.1" 200 37106
>>> for app in apps:
... print(app.name)
Indices and tables¶
Developer interface¶
Clappform Python API wrapper
- class clappform.Clappform(base_url: str, username: str, password: str, workers: int = 6, tries: int = 4, backoff_factor: int = 1)¶
Bases:
objectClappformclass is used to more easily interact with an Clappform environement through the API.- Parameters:
base_url (str) – Base URL of a Clappform environment e.g.
https://app.clappform.com.workers (int) – Number of workers to use in ThreadPoolExecutor and Connectionpool. Defaults to
min(32, os.cpu_count() + 4).tries (int) – Number of times to try (not retry) before giving up.
backoff_factor (int) – Backoff factor to multiply delay with.
Most routes of the Clappform API require authentication. For the routes in the Clappform API that require authentication
Clappformwill do the authentication for you.In the example below
c.get(r.App())uses a route which requires authentication.Clappformdoes the authentication for you.Usage:
>>> from clappform import Clappform >>> import clappform.dataclasses as r >>> c = Clappform( ... "https://app.clappform.com", ... "j.doe@clappform.com", ... "S3cr3tP4ssw0rd!", ... ) >>> apps = c.get(r.App()) >>> for app in apps: ... print(app.name)
The
get(),create(),update()anddelete()methods can act on any object that implements theclappform.dataclasses.ResourceTypeinterface.- The currently supported resources are:
- session: Session¶
Session for all HTTP requests.
- workers: int¶
Number of workers to use in ThreadPoolExecutor and Connectionpool. defaults to:
min(32, os.cpu_count() + 4).
- executor¶
ThreadPoolExecut obj to submit large amount of requests to.
- auth() None¶
Sends an authentication request. Gets called whenever authentication is required.
The
_authattribute is set to a newly constructedclappform.dataclasses.Authobject.
- verify_auth() ApiResponse¶
Verify against the API if the authentication is valid.
- Returns:
API response object
- Return type:
- get(resource, item=None)¶
Get a one or list of resources.
- Parameters:
resource – Any object of
clappform.dataclasses.ResourceTypeitem (dict) – Optional only useful when resource argument is of type
clappform.dataclasses.Collection.
Usage:
>>> from clappform import Clappform >>> import clappform.dataclasses as r >>> c = Clappform( ... "https://app.clappform.com", ... "j.doe@clappform.com", ... "S3cr3tP4ssw0rd!" ... ) >>> collection = c.get(r.Collection(id="clappform", slug="us_presidents")) >>> c.get(collection, item={"_id", "6475c76276ffd5e8da000b2c"}) {'_id': '6475c76276ffd5e8da000b2c', 'name': "George Washington"}
- Returns:
One or a list of resources
- create(resource, item=None)¶
Crete a resource.
- Parameters:
resource – Any object of
clappform.dataclasses.ResourceTypeitem (dict) – Optional only useful when resource argument is of type
clappform.dataclasses.Collection.
Usage:
>>> from clappform import Clappform >>> import clappform.dataclasses as r >>> c = Clappform( ... "https://app.clappform.com", ... "j.doe@clappform.com", ... "S3cr3tP4ssw0rd!" ... ) >>> new_app = r.App( ... id="uspresidents", ... name="US Presidents", ... description="US Presidents Dashboard", ... settings={} ... ) >>> c.create(new_app) App(collections=0, default_page='', description='US Presidents Dashboard...
- Returns:
Newly created resource
- update(resource, item=None)¶
Update a resource.
- Parameters:
resource – Any object of
clappform.dataclasses.ResourceTypeitem (dict) – Optional only useful when resource argument is of type
clappform.dataclasses.Collection.
Usage:
>>> from clappform import Clappform >>> import clappform.dataclasses as r >>> c = Clappform( ... "https://app.clappform.com", ... "j.doe@clappform.com", ... "S3cr3tP4ssw0rd!" ... ) >>> app = c.get(r.App(id="uspresidents")) >>> app.description = "Dashboard of US Presidents" >>> c.update(app) App(collections=0, default_page='', description='Dashboard of US Preside...
- Returns:
Updated resource
- delete(resource, item=None)¶
Delete a resource.
Usage:
>>> from clappform import Clappform >>> import clappform.dataclasses as r >>> c = Clappform( ... "https://app.clappform.com", ... "j.doe@clappform.com", ... "S3cr3tP4ssw0rd!", ... ) >>> app = c.get(r.App(id="uspresidents")) >>> c.delete(app) ApiResponse(code=200, message='Successfully deleted app with ID: uspresi...
- Returns:
Confirmation of deletion.
- Return type:
- aggregate_dataframe(options: dict, max_workers=None) Generator[list[dict], None, None]¶
Aggregate a dataframe
- read_dataframe(query, limit: int = 100, max_workers=None) Generator[list[dict], None, None]¶
Read a dataframe.
- Parameters:
query (
clappform.dataclasses.Query|clappform.dataclasses.Collection) – Query to for retreiving data. When Query is of typeclappform.dataclasses.Collectioneverything inside the collection is retreived.limit (int) – Amount of records to retreive per request.
max_workers (int) – Optional number of workers to use in thread pool.
Usage:
>>> from clappform import Clappform >>> import clappform.dataclasses as r >>> import pandas as pd >>> c = Clappform( ... "https://app.clappform.com", ... "j.doe@clappform.com", ... "S3cr3tP4ssw0rd!" ... ) >>> query = c.get(r.Query(slug="foo") >>> list_df = [] >>> for chunck in c.read_dataframe(query): ... list_df.extend(chunck)
- Returns:
Generator to read dataframe
- Return type:
Generator
- write_dataframe(df: DataFrame, collection: Collection, size: int = 100, max_workers=None)¶
Write Pandas DataFrame to collection.
- Parameters:
df (
pandas.DataFrame) – Pandas DataFrame to write to collectioncollection (
clappform.dataclasses.Collection) – Collection to hold DataFrame recordssize (int) – Size of each chunk. Defaults to:
100interval_timeout (int) – Optional time to sleep per request, defaults to:
0.0.
- empty_dataframe(collection) ApiResponse¶
Empty a dataframe.
- Parameters:
collection (clappform.dataclasses.Collection) – Collection to append data to.
- Returns:
API response object
- Return type:
- export_app(app) dict¶
Export an app.
- Parameters:
app (
str|clappform.dataclasses.App) – App to export- Returns:
Exported App
- Return type:
- import_app(app: dict, data_export: bool = False) ApiResponse¶
Import an app.
- Parameters:
app (dict) – Exported app object.
- Returns:
Api Response Object
- Return type:
- transfer_collections(src: dict, dest, max_workers=None) Generator[ApiResponse, None, None]¶
Transfer data from collection(s) from an app to a destination.
Destination is an instance of the
clappform.Clappform. This method recreates all the data from all collections of an app to the same app and collections on anotherclappform.Clappform.- Parameters:
src (dict) – App dictionary or the value of running
export_app().dest (
clappform.Clappform) – Destination clappform environment.
- Returns:
Generator of
clappform.dataclasses.ApiResponse- Return type:
Generator
- current_user(extended: bool = False) User¶
Get
clappform.dataclasses.Userobject of the current user.- Parameters:
extended (bool) – Optional retreive fully expanded user, defaults to
false.- Returns:
User object.
- Return type:
clappform.dataclasses¶
This module contains the set of Clappform’s return objects.
- class clappform.dataclasses.ApiResponse(code: int, message: str, response_id: str, **kwargs)¶
Bases:
objectData class to represent generic API response.
- Parameters:
- class clappform.dataclasses.Auth(access_token: str, refresh_expiration: int, refresh_token: str)¶
Bases:
objectAuthentication dataclass.
- Parameters:
access_token (str) – Bearer token to be used in a HTTP authorization header.
refresh_expiration (int) – Integer representing the when the
refresh_tokenis invalid.refresh_token (str) – Bearer token to be used get new
access_token.
- refresh_expiration: int¶
Integer representing the when the
refresh_tokenis invalid.
- refresh_token: str¶
Bearer token to be used get new
access_token.
- is_token_valid() bool¶
Returns boolean answer to: is the
access_tokenstill valid?- Returns:
Validity of
access_token- Return type:
- class clappform.dataclasses.Version(api: str | None = None, web_application: str | None = None, web_server: str | None = None)¶
Bases:
objectVersion dataclass.
- Parameters:
- class clappform.dataclasses.ResourceType¶
Bases:
objectResourceType is used as an interface for
clappform.Clappform. Any class that uses this class as a base can be used withclappform.Clappform’s methods.- abstract one_or_all_path() str¶
Return the path to retreive one or all resources.
- Returns:
Resource HTTP path
- Return type:
- abstract one_path() str¶
Return the path to retreive this Resource
- Returns:
Resource HTTP path
- Return type:
- class clappform.dataclasses.App(collections: int | None = None, default_page: str | None = None, description: str | None = None, groups: int | None = None, id: str = <property object>, name: str | None = None, settings: dict | None = None, extended: bool = False)¶
Bases:
ResourceTypeApp resource type.
- Parameters:
collections (int) – Number of collections this app has.
default_page (str) – Page to view when opening app.
description (str) – Description below app name.
groups (int) – Nuber of groups in an app.
id (str) – Used internally to identify app.
name (str) – Name of the app.
settings (dict) – Settings to configure app.
extended (bool) – Whether fully expanded app object with
get.
Usage:
>>> from clappform import Clappform >>> import clappform.dataclasses as r >>> c = Clappform( ... "https://app.clappform.com", ... "j.doe@clappform.com", ... "S3cr3tP4ssw0rd!", ... ) >>> new_app = r.App( ... id="uspresidents", ... name="US Presidents", ... description="US Presidents Dashboard", ... settings={} ... ) >>> c.create(new_app) App(collections=0, default_page='', description='US Presidents Dashboard', g... >>> app = c.get(r.App(id="uspresidents")) >>> c.delete(app) ApiResponse(code=200, message='Successfully deleted app with ID: uspresident... >>> for app in c.get(r.App()): ... print(app.name)
- collections: int = None¶
Number of collections this app has. If
extended=Truethis will be a list of collections.
- class clappform.dataclasses.Collection(app: str = <property object>, slug: str = <property object>, database: str | None = None, name: str | None = None, description: str | None = None, is_encrypted: bool | None = None, is_locked: bool | None = None, is_logged: bool | None = None, queries: list | None = None, sources: list | None = None, id: int | None = None, extended: int = 0)¶
Bases:
ResourceTypeCollection resource type.
- Parameters:
app (str) – Id of the app collection belongs to.
slug (str) – Unique id of the collection.
database (str) – Database location to store documents, e.g.
MONGOorDATALAKE.name (str) – Display name of the collection.
description (str) – Description below collection name.
extended=1id (int) – Numeric ID of the collection used for internal identification.
extended=1is_encrypted (bool) – Use of encryption on this collection.
extended=1is_locked (bool) – Read only permissions on collection.
extended=1is_logged (bool) – HTTP Access logging on this collection.
extended=1sources (bool) – List of locations the data originates from.
extended=1queries (list) – Queries that query this collection’s data.
extended=2extended (bool) – At what level to expand collection object with
get.
Usage:
>>> from clappform import Clappform >>> import clappform.dataclasses as r >>> c = Clappform( ... "https://app.clappform.com", ... "j.doe@clappform.com", ... "S3cr3tP4ssw0rd!", ... ) >>> app = c.get(r.App(id="uspresidets")) >>> new_collection = r.Collection( ... app=app, ... database="MONGO", ... name="United States Presidents", ... slug="presidents", ... description="All presidents of the United Stated of America" ... ) >>> c.create(new_collection) Collection(app='uspresidents', slug='presidents', database='MONGO', name='Un... >>> collection = c.get(r.Collection(app="uspresidents", slug="presidents")) >>> c.delete(collection) ApiResponse(code=200, message='Successfully deleted collection with slug: pr... >>> for collection in c.get(r.Collection()): ... print(f"{collection.app}: {collection.slug}")
- database: str = None¶
Database location where this collection is stored, e.g.
"MONGO"or"DATALAKE".
- is_locked: bool = None¶
Whether this collection is write protected. Collection is read only. Default is
False.
- extended: int = 0¶
Used by
getto gauge whether to fetch fully expanded app object. Allowed values:0-3. Defaults to0.
- property app: str¶
App id this collection belong to. This can be of type
clappform.dataclasses.Apporstr.
- one_or_all_path()¶
Return the path to retreive one or all collections.
- Returns:
Collection HTTP path
- Return type:
- one_path() str¶
Return the path to retreive this Collection
- Returns:
Collection HTTP path
- Return type:
- all_path() str¶
Return the path to retreive all Collections.
- Returns:
Collection HTTP path
- Return type:
- create_path() str¶
Return the path to create a Collection.
- Returns:
Collection HTTP path
- Return type:
- one_item_path(item: str) str¶
Return the route used for creating and deleting items.
- Returns:
Item HTTP path
- Return type:
- class clappform.dataclasses.Query(app: str = <property object>, collection: str = <property object>, data_source: str | None = None, export: bool | None = None, id: int | None = None, name: str | None = None, query: list | None = None, slug: str | None = None, source_query: str | None = None, modules: list | None = None, primary: bool | None = None, settings: dict | None = None)¶
Bases:
ResourceTypeCollection resource type.
Usage:
>>> from clappform import Clappform >>> import clappform.dataclasses as r >>> c = Clappform( ... "https://app.clappform.com", ... "j.doe@clappform.com", ... "S3cr3tP4ssw0rd!", ... ) >>> collection = c.get(r.Collection(app="uspresidets", slug="presidents")) >>> new_query = r.Query( ... collection=collection, ... data_source="app", ... query=[], ... name="all presidents", ... slug="f1cb2ba5-64a7-4056-99d5-7d639557970f", ... ) >>> c.create(new_collection) Query(app='uspresidets', collection='presidents', data_source='app', export=... >>> query = c.get(r.Query(slug="f1cb2ba5-64a7-4056-99d5-7d639557970f")) >>> c.delete(query) ApiResponse(code=200, message='Successfully deleted query with slug: f1cb2ba... >>> for query in c.get(r.Query()): ... print(f"{query.app}/{query.collection}: {query.slug}")
- property app: str¶
App id this query belong to. This can be of type
clappform.dataclasses.Apporstr.
- property collection: str¶
Collection slug this query refers to. This can be of type
clappform.dataclasses.Collectionorstr.
- one_or_all_path() str¶
Return the path to retreive one or all resources.
- Returns:
Resource HTTP path
- Return type:
- one_path() str¶
Return the route used to retreive the Query.
- Returns:
Query HTTP resource path
- Return type:
- all_path() str¶
Return the route used to retreive the Query.
- Returns:
Query HTTP resource path
- Return type:
- class clappform.dataclasses.Actionflow(id: int | None = None, name: str | None = None, slug: str | None = None, category: str | None = None, fast: bool | None = None, multiple: bool | None = None, settings: dict | None = None, start_keys: list | None = None, extra_information: list | None = None, cronjobs: list | None = None, tasks: list | None = None)¶
Bases:
ResourceTypeActionflow resource type.
Usage:
>>> from clappform import Clappform >>> import clappform.dataclasses as r >>> c = Clappform( ... "https://app.clappform.com", ... "j.doe@clappform.com", ... "S3cr3tP4ssw0rd!", ... ) >>> new_actionflow = r.Actionflow( ... name="Periodic housekeeping", ... settings={}, ... ) >>> c.create(new_collection) Actionflow(id=48, name='Periodic housekeeping', settings={}, cronjobs=None, ... >>> actionflow = c.get(r.Actionflow(id=48)) >>> c.delete(actionflow) ApiResponse(code=200, message='Deleted action flow.', response_id='648083113...v >>> for af in c.get(r.Actionflow()): ... print(f"{af.id}: {af.name}")
- one_or_all_path() str¶
Return the path to retreive one or all resources.
- Returns:
Resource HTTP path
- Return type:
- class clappform.dataclasses.Questionnaire(name: str | None = None, id: int | None = None, created_at: int | None = None, active: bool | None = None, created_by: dict | None = None, latest_version: dict | None = None, versions: list | None = None, settings: dict | None = None, extended: bool = False)¶
Bases:
ResourceTypeQuestionnaire dataclass.
- one_or_all_path() str¶
Return the path to retreive one or all resources.
- Returns:
Resource HTTP path
- Return type:
- class clappform.dataclasses.User(email: str | None = None, extra_information: dict | None = None, first_name: str | None = None, last_name: str | None = None, is_active: bool | None = None, id: int | None = None, phone: str | None = None, messages: dict | None = None, last_online: int | None = None, permissions: list[str] | None = None, roles: list[dict] | None = None, password: str | None = None, extended: bool = False)¶
Bases:
ResourceTypeUser resource type.
Usage:
>>> from clappform import Clappform >>> import clappform.dataclasses as r >>> c = Clappform( ... "https://app.clappform.com", ... "j.doe@clappform.com", ... "S3cr3tP4ssw0rd!", ... ) >>> user = c.get(r.User(email="j.doe@clappform.com") >>> new_user = r.User( ... email="g.washington@clappform.com", ... first_name="George", ... last_name="Washington", ... password="HavntGotWoodenTeeth", ... ) >>> c.create(new_user) User(email='g.washington@clappform.com', extra_information={}, first_name='G... >>> query = c.get(r.Query(slug="f1cb2ba5-64a7-4056-99d5-7d639557970f")) >>> c.delete(query) ApiResponse(code=200, message='Successfully deactivated user, with email: g.... >>> for user in c.get(r.User()): ... print(f"{user.email}: {user.first_name} {user.last_name}")
- extra_information: dict = None¶
Dictionary object describing extra related information about the user.
- messages: dict = None¶
Dictionary object containing notifications, emails, sms or whatsapp messages.
extended=True
clappform.exceptions¶
This module contains the set of Clappform’s exceptions.
- exception clappform.exceptions.HTTPError(*args, **kwargs)¶
Bases:
HTTPErrorAn HTTP error occurred.
- exception clappform.exceptions.PaginationError(*args, **kwargs)¶
Bases:
HTTPErrorA pagination error in paginated response occurred.
- exception clappform.exceptions.PaginationTotalError(*args, **kwargs)¶
Bases:
PaginationErrorA total error in paginated response occurred.
- exception clappform.exceptions.PaginationKeyError(*args, **kwargs)¶
Bases:
PaginationErrorA key error in paginated response occurred.