cmempy is a Python API wrapper around the eccenca Corporate Memory HTTP APIs which can be used to rapidly script processes which interact with Corporate Memory. cmempy is also the underlying Python module which powers the cmemc - Command Line Interface.


cmempy is published as an Apache 2 licensed open source python package at, hence you are able to install it with a simple pip command:

$ pip install cmem-cmempy

Configure a Connection

The used Corporate Memory connection is configured by providing environment variables similar to cmemc (Configuration with Environment Variables).

These environment variables can be created and changed in your code or used from the process which executes your python code (e.g. your shell).

The following table lists all processed environment variables:

VariableDescriptionDefault Value
CMEM_BASE_URIBase URL of your Corporate Memoryhttp://docker.local
DI_API_ENDPOINTData Integration API endpointCMEM_BASE_URI/dataintegration
DP_API_ENDPOINTData Platform API endpointCMEM_BASE_URI/dataplatform
OAUTH_TOKEN_URIOAuth 2.0 Token endpointCMEM_BASE_URI/auth/realms/cmem/protocol/openid-connect/token
OAUTH_GRANT_TYPEOAuth 2.0 grant type (password or client_credentials)client_credentials
OAUTH_USERUsername to retrieve the tokenadmin
OAUTH_PASSWORDPassword to retrieve the tokensecret
OAUTH_CLIENT_IDOAuth 2.0 client idcmem-service-account
OAUTH_CLIENT_SECRETOAuth 2.0 client secretsecret
SSL_VERIFYVerify SSL certs for API requestsTrue
REQUESTS_CA_BUNDLEPath to the CA Bundle file (.pem)Internal path to included CA bundle

Commented Example

Here is a commented code example how to configure and use cmempy.

The example demonstrates, how to execute SPARQL queries on DataPlatform, as well as how to work with the DataIntegration workspace and retrieve workflow status information:

"""Basic example, how to use cmempy"""

from os import environ

from cmem.cmempy.workspace.projects.project import get_projects
from cmem.cmempy.workflow import get_workflows
from cmem.cmempy.workspace.activities.taskactivity import get_activity_status
from cmem.cmempy.queries import SparqlQuery

# setup the environment for the connection to Corporate Memory
environ["CMEM_BASE_URI"] = "http://docker.local"
environ["OAUTH_GRANT_TYPE"] = "client_credentials"
environ["OAUTH_CLIENT_ID"] = "cmem-service-account"
environ["OAUTH_CLIENT_SECRET"] = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"

# this query simply lists 5 resource subjects from the triple store

# the default result is a JSON structure according to the W3C standard
# seeAlso:
results = SparqlQuery(QUERY_TEXT).get_results()

# loop over project descriptions
for project in get_projects():
    project_id = project["name"]
    print("Project: {}:".format(project_id))

    # loop over workflow ids for a project
    for workflow_id in get_workflows(project_id):
        # get the status object of a specific workflow
        status = get_activity_status(project_id, workflow_id)
        message = status["message"]
        print("- Workflow: {} ({}):".format(workflow_id, message))

Starting this script should result in an output similar to this:

$ python
  "head": {
    "vars": [ "s" ]
  } ,
  "results": {
    "bindings": [
        "s": { "type": "uri" , "value": "" }
      } ,
        "s": { "type": "uri" , "value": "" }
      } ,
        "s": { "type": "uri" , "value": "" }
      } ,
        "s": { "type": "uri" , "value": "" }
      } ,
        "s": { "type": "uri" , "value": "" }

Project: cmem:
- Workflow: my-workflow (Idle):