Welcome to Clappform’s API Wrapper¶
Indices and tables¶
Developer interface¶
Clappform Python API wrapper
- class clappform.Clappform(base_url: str, username: str, password: str, timeout: int = 2)¶
Bases:
objectClappformclass is used to more easily interact with an Clappform environement through the API.- Parameters:
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_apps()uses a route which requires authentication.Clappformdoes the authentication for you.Usage:
>>> from clappform import Clappform >>> c = Clappform( ... "https://app.clappform.com", ... "j.doe@clappform.com", ... "S3cr3tP4ssw0rd!", ... ) >>> apps = c.get_apps() >>> for app in apps: ... print(app.name)
- 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_apps() list[clappform.dataclasses.App]¶
Gets all apps.
Usage:
>>> from clappform import Clappform >>> c = Clappform( ... "https://app.clappform.com", ... "j.doe@clappform.com", ... "S3cr3tP4ssw0rd!", ... ) >>> apps = c.get_apps()
- Returns:
List of
clappform.dataclasses.Appor empty list if there are no apps.- Return type:
- get_app(app, extended: bool = False) App¶
Get a single app.
- Parameters:
app (
str|clappform.dataclasses.App) – App to get from the APIextended (bool) – Optional retreive fully expanded app, defaults to
false.
Usage:
>>> from clappform import Clappform >>> c = Clappform( ... "https://app.clappform.com", ... "j.doe@clappform.com", ... "S3cr3tP4ssw0rd!" ... ) >>> app = c.get_app("clappform") >>> app = c.get_app(app)
- Returns:
App Object
- Return type:
- create_app(app_id: str, name: str, desc: str, settings: dict) App¶
Create a new app.
- Parameters:
Usage:
>>> from clappform import Clappform >>> c = Clappform( ... "https://app.clappform.com", ... "j.doe@clappform.com", ... "S3cr3tP4ssw0rd!" ... ) >>> new_app = c.create_app("foo", "Foo", "Foo Bar", {})
- Returns:
Newly created app
- Return type:
- update_app(app) App¶
Update an existing app.
- Parameters:
app (clappform.dataclasses.App) – Modified app object.
Usage:
>>> from clappform import Clappform >>> c = Clappform( ... "https://app.clappform.com", ... "j.doe@clappform.com", ... "S3cr3tP4ssw0rd!", ... ) >>> app = c.get_app("foo") >>> app.name = "Bar" >>> app = c.update_app(app)
- Returns:
Updated app object
- Return type:
- delete_app(app) ApiResponse¶
Delete an app.
- Parameters:
app (
str|clappform.dataclasses.App) – App to delete from the API
Usage:
>>> from clappform import Clappform >>> c = Clappform( ... "https://app.clappform.com", ... "j.doe@clappform.com", ... "S3cr3tP4ssw0rd!" ... ) >>> c.delete_app("foo")
- Returns:
Response from the API
- Return type:
- get_collections(app=None, extended: int = 0) list[clappform.dataclasses.Collection]¶
Get all the collections.
The extended parameter allows an integer value from 0 - 3.
- Parameters:
app (clappform.dataclasses.Collection) – Optional return only collections from specified app, default:
None.extended (int) – Optional level of detail for each collection, default:
0.
Usage:
>>> from clappform import Clappform >>> c = Clappform( ... "https://app.clappform.com", ... "j.doe@clappform.com", ... "S3cr3tP4ssw0rd!", ... ) >>> app = c.get_app("foo") >>> collections = c.get_collections(extended=3) >>> collections = c.get_collections(app=app)
- Raises:
ValueError – extended value not in [0, 1, 2 ,3]
- Returns:
List of Collections or empty list if there are no collections
- Return type:
- get_collection(collection, app=None, extended: int = 0, offset: int = 0) Collection¶
Get a single collection.
The extended parameter allows an integer value from 0 - 3.
- Parameters:
collection (
str|clappform.dataclasses.Collection) – Identifier for collection to retreive.app (
str|clappform.dataclasses.App) – Required when collection is of typestr, default:None.extended (int) – Optional level of detail for each collection, default:
0.offset (int) – Offset from which to retreive items, only useful when extended is
3.
Usage:
>>> from clappform import Clappform >>> c = Clappform( ... "https://app.clappform.com", ... "j.doe@clappform.com", ... "S3cr3tP4ssw0rd!", ... ) >>> app = c.get_app("foo") >>> collection = c.get_collection("bar", app=app) >>> collection = c.get_collection("bar", app="foo") >>> collection = c.get_collection(collection)
and
appparameter isNone.- Raises:
ValueError – extended value not in [0, 1, 2 ,3]
TypeError – app kwargs must be of type
clappform.dataclasses.Apporstr.
- Returns:
Collection Object
- Return type:
- create_collection(app, slug: str, name: str, desc: str, db: str = 'MONGO') Collection¶
Create a new Collection.
- Parameters:
app (
str|clappform.dataclasses.App.) – App identifier to create collection for.slug (str) – Name used for internal identification.
name (str) – Name of the collection.
desc (str) – Description of what data the collection holds.
db (str) – Database where collection is stored. Valid values for
dbareMONGOandDATALAKE, defaults to:MONGO
Usage:
>>> from clappform import Clappform >>> c = Clappform( ... "https://app.clappform.com", ... "j.doe@clappform.com", ... "S3cr3tP4ssw0rd!", ... ) >>> app = c.get_app("foo") >>> new_collection = c.create_collection( ... app, ... "bar", ... "Bar", ... "Bar Collection" ... )
- Returns:
New Collection Object
- Return type:
- update_collection(collection: Collection) Collection¶
Update an existing collection.
- Parameters:
collection (clappform.dataclasses.Collection) – Collection object to update
Usage:
>>> from clappform import Clappform >>> c = Clappform( ... "https://app.clappform.com", ... "j.doe@clappform.com", ... "S3cr3tP4ssw0rd!" ... ) >>> collection = c.get_collection("bar", app="foo") >>> collection.name = "Spam & Eggs Collection" >>> collection = c.update_collection(collection)
- Raises:
TypeError – collection arg is not of type
clappform.dataclasses.Collection- Returns:
Updated Collection object
- Return type:
- delete_collection(collection: Collection) ApiResponse¶
Delete a collection.
- Parameters:
collection (clappform.dataclasses.Collection) – Collection to remove
Usage:
>>> from clappform import Clappform >>> c = Clappform( ... "https://app.clappform.com", ... "j.doe@clappform.com", ... "S3cr3tP4ssw0rd!" ... ) >>> collection = c.get_collection("bar", app="foo") >>> c.delete_collection(collection)
- Returns:
API reponse object
- Return type:
- get_queries() list[clappform.dataclasses.Query]¶
Get all queries.
Usage:
>>> from clappform import Clappform >>> c = Clappform( ... "https://app.clappform.com", ... "j.doe@clappform.com", ... "S3cr3tP4ssw0rd!", ... ) >>> queries = c.get_queries()
- Returns:
List of Query objects
- Return type:
- get_query(query) Query¶
Get single query.
- Parameters:
query (
str|clappform.dataclasses.Query) – Query identifier
Usage:
>>> from clappform import Clappform >>> c = Clappform( ... "https://app.clappform.com", ... "j.doe@clappform.com", ... "S3cr3tP4ssw0rd!", ... ) >>> query = c.get_query("foo")
- Returns:
Query object
- Return type:
clappfrom.dataclasses.Query
- source_query(query: Query) ApiResponse¶
Source a query
- Parameters:
query (clappform.dataclasses.Query) – Query to source.
- Returns:
API response object
- Return type:
- create_query(data_source: str, query: list, name: str, slug: str, collection=None) Query¶
Create a new query.
- Parameters:
data_source (str) – Source of the data either
apporfilterbar.query (list) –
- Query that follows the specification described in
name (str) – Name for the query
slug (str) – Internal identification string
collection (clappform.dataclasses.Collection) – Only required when the
data_sourceargument holds the"app"value.
- Returns:
New Query object
- Return type:
- update_query(query: Query) Query¶
Update an existing Query.
- Parameters:
query (clappform.dataclasses.Query) – Query object to update.
Usage:
>>> from clappform import Clappform >>> c = Clappform( ... "https://app.clappform.com", ... "j.doe@clappform.com", ... "S3cr3tP4ssw0rd!" ... ) >>> query = c.get_query("foo") >>> query.name = "Bar Query" >>> query = c.update_query(query)
- Returns:
Updated Query object
- Return type:
- delete_query(query) ApiResponse¶
Delete a Query.
- Parameters:
query (
str|clappform.dataclasses.Query) – Query identifier- Returns:
API response object
- Return type:
- aggregate_dataframe(options: dict, interval_timeout: int = 0.1)¶
Aggregate a dataframe
- Parameters:
options (dict) – Options for dataframe aggregation.
- Returns:
Generator to read dataframe
- Return type:
generator
- read_dataframe(query, limit: int = 100, interval_timeout: int = 0.1)¶
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.
interval_timeout (int) – Optional time to sleep per request, defaults to:
0.1.
Usage:
>>> from clappform import Clappform >>> c = Clappform( ... "https://app.clappform.com", ... "j.doe@clappform.com", ... "S3cr3tP4ssw0rd!" ... ) >>> query = c.get_query("foo") >>> it = c.read_dataframe(query) >>> for i in it: ... print(i)
- Returns:
Generator to read dataframe
- Return type:
generator
- write_dataframe(df: DataFrame, collection: Collection, chunk_size: int = 100, interval_timeout: int = 0.1)¶
Write Pandas DataFrame to collection.
- Parameters:
df (
pandas.DataFrame) – Pandas DataFrame to write to collectioncollection (
clappform.dataclasses.Collection) – Collection to hold DataFrame recordschunk_size (int) – defaults to:
100interval_timeout (int) – Optional time to sleep per request, defaults to:
0.1.
- append_dataframe(collection, array: list[dict]) ApiResponse¶
Append data to a collection.
- Parameters:
collection (clappform.dataclasses.Collection) – Collection to append data to.
- Returns:
API response object
- Return type:
- sync_dataframe(collection, array: list[dict]) ApiResponse¶
Synchronize a dataframe.
Synchronize replaces the existing data with data found in
array.- Parameters:
collection (clappform.dataclasses.Collection) – Collection to append data to.
- Returns:
API response object
- Return type:
- empty_dataframe(collection) ApiResponse¶
Empty a dataframe.
- Parameters:
collection (clappform.dataclasses.Collection) – Collection to append data to.
- Returns:
API response object
- Return type:
- get_actionflows() list[clappform.dataclasses.Actionflow]¶
Get all actionflows.
- Returns:
List of
clappform.dataclasses.Actionflowor empty list if there are no actionflows.- Return type:
- get_actionflow(actionflow) Actionflow¶
Get single actionflow.
- Parameters:
actionflow (
int|clappform.dataclasses.App) – Actionflow to get from the API
Usage:
>>> from clappform import Clappform >>> c = Clappform( ... "https://app.clappform.com", ... "j.doe@clappform.com", ... "S3cr3tP4ssw0rd!", ... ) >>> af = c.get_actionflow(1) >>> af = c.get_actionflow(af)
- Returns:
Actionflow Object
- Return type:
- create_actionflow(name: str, settings: dict) Actionflow¶
Create a new actionflow.
- Parameters:
- Returns:
New Actionflow object
- Return type:
- update_actionflow(actionflow: Actionflow) Actionflow¶
Update an existing Actionflow.
- Parameters:
actionflow (clappform.dataclasses.Actionflow) – Actionflow object to update.
- Returns:
Updated Actionflow object
- Return type:
- delete_actionflow(actionflow) ApiResponse¶
Delete a Actionflow.
- Parameters:
actionflow (
int|clappform.dataclasses.Actionflow) – Actionflow identifier- Returns:
API response object
- Return type:
- get_questionnaires(extended: bool = False) list[clappform.dataclasses.Questionnaire]¶
Get all questionnaires
- Parameters:
extended (bool) – Optional retreive fully expanded questionnaires, defaults to
false.- Returns:
List of
clappform.dataclasses.Questionnaireor empty list if there are no questionnaires.- Return type:
- get_questionnaire(questionnaire, extended: bool = False) Questionnaire¶
Get a questionnaire
- Parameters:
extended (bool) – Optional retreive fully expanded questionnaire, defaults to
false.- Returns:
Qustionnaire Object
- Return type:
- create_questionnaire(name: str, settings: dict) ApiResponse¶
Create a new questionnaire.
- Parameters:
- Returns:
ApiResponse object
- Return type:
- update_questionnaire(questionnaire: Questionnaire, settings: dict) Questionnaire¶
Update an existing Questionnaire.
- Parameters:
questionnaire (clappform.dataclasses.Questionnaire) – Questionnaire object to update.
settings (dict) – Settings object
- Returns:
Updated Questionnaire object
- Return type:
- delete_questionnaire(questionnaire)¶
Delete a Questionnaire.
- Parameters:
questionnaire (
int|clappform.dataclasses.Questionnaire) – Questionnaire identifier- 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:
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, web_application: str, web_server: str)¶
Bases:
objectVersion dataclass.
- Parameters:
- class clappform.dataclasses.AbstractBase¶
Bases:
objectAbstractBase is used as a base class for dataclasses.
AbstractBasecontains only one abstract method. Any class that inherits fromAbstractBaseis required to implementpath.
- class clappform.dataclasses.App(collections: int, default_page: str, description: str, groups: int, id: str, name: str, settings: dict)¶
Bases:
AbstractBaseApp dataclass.
- 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.
- static format_path(app: str, extended: bool = False) str¶
Return the route used to retreive the App.
- Returns:
App’s HTTP resource path.
- Return type:
- static format_collection_path(app: str) str¶
Return the base route used to get and create the App’s collections’.
- Returns:
App’s collection HTTP get and create path.
- Return type:
- class clappform.dataclasses.Collection(app: str, database: str, name: str, slug: str, items: int | 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)¶
Bases:
AbstractBaseCollection dataclass.
- static format_base_path(app: str, extended: int = 0) str¶
Return the route used for getting all and creating collections.
- Returns:
Collection getting and creating HTTP path
- Return type:
- base_path(extended: int = 0) str¶
Return the route used for getting all and creating collections.
- Returns:
Collection getting and creating HTTP path
- Return type:
- static format_path(app: str, collection: str, extended: int = 0) str¶
Return the route used to retreive the collection.
- class clappform.dataclasses.Query(app: str, collection: str, data_source: str, export: bool, id: int, name: str, query: list, slug: str, source_query: str, modules: list | None = None)¶
Bases:
AbstractBaseQuery dataclass.
- static format_path(query: str) str¶
Return the route used to retreive the Query.
- Returns:
Query HTTP resource path
- Return type:
- class clappform.dataclasses.Actionflow(id: int, name: str, settings: dict, cronjobs: list | None = None, tasks: list | None = None)¶
Bases:
AbstractBaseActionflow dataclass.
- class clappform.dataclasses.Questionnaire(name: str, id: int, created_at: int, active: bool, created_by: dict, latest_version: dict, versions: list | None = None)¶
Bases:
AbstractBaseQuestionnaire dataclass.
clappform.exceptions¶
This module contains the set of Clappform’s exceptions.