Api Client

The following tutorial demonstarates how to access the api with python


In [56]:
#import libraries
import coreapi
import json

In [57]:
# so far the api is restricted and only accasible with authentication
auth = coreapi.auth.BasicAuthentication(
    username='janekg89',
    password='test'
)
client = coreapi.Client(auth=auth)

In [58]:
# get the api scema
document = client.get("http://127.0.0.1:8000/api/")
print(document.title)
print(document.url)


Tellurium Web API
http://127.0.0.1:8000/api/

In [59]:
#what can I do with the archvies
print(document["api"]["archives"])
# keys in [] are optional params


{
    list([limit], [offset], [name], [task_id], [tags], [created], [search])
    create(file, [name], [created], [md5], [task_id], [entries], [tags])
    read(uuid, [name], [task_id], [tags], [created], [search])
    update(uuid, file, [name], [created], [md5], [task_id], [entries], [tags], [name], [task_id], [tags], [created], [search])
    partial_update(uuid, [name], [file], [created], [md5], [task_id], [entries], [tags], [name], [task_id], [tags], [created], [search])
    delete(uuid, [name], [task_id], [tags], [created], [search])
}

In [135]:
#what can I do with the tags
print(document["tags"])
# keys in [] are optional params


{
    list([name], [type])
    create(name, type)
    read(uuid, [name], [type])
    update(uuid, name, type, [name], [type])
    partial_update(uuid, [name], [type], [name], [type])
    delete(uuid, [name], [type])
}

In [136]:
#what can I do with the users
print(document["users"])
# keys in [] are optional params


{
    list([is_staff], [username], [search])
    create(username, [email], [is_staff])
    read(id, [is_staff], [username], [search])
    update(id, username, [email], [is_staff], [is_staff], [username], [search])
    partial_update(id, [username], [email], [is_staff], [is_staff], [username], [search])
    delete(id, [is_staff], [username], [search])
}

Examples of some querys


In [137]:
#search so far by id with foreignkey
data = client.action(document,["archives", "list"], params={"tags":1} )
print(json.dumps(data,indent=4))


[
    {
        "name": "CombineArchiveShowCase.omex",
        "file": "http://127.0.0.1:8001/media/archives/CombineArchiveShowCase.omex",
        "created": "2017-11-07T14:07:31.105147Z",
        "md5": "feee500260a73f10040b8ba0681936e5",
        "task_id": "",
        "tags": [
            "http://127.0.0.1:8001/api/tags/f3f0af48-fa67-44db-861a-9deb9c67c61e/",
            "http://127.0.0.1:8001/api/tags/59dafcf2-82c0-4f48-bb4d-3954cacc2b47/",
            "http://127.0.0.1:8001/api/tags/74afbb79-9ba9-4795-9677-0fbfe017ab51/",
            "http://127.0.0.1:8001/api/tags/8503b4dd-43ce-4cee-a0bd-fbf5df89bf0d/",
            "http://127.0.0.1:8001/api/tags/36b8842e-b93d-411d-890c-882e9ef7272e/"
        ],
        "uuid": "0e602a58-432d-4470-b70d-e26073f4ec49"
    },
    {
        "name": "L1V3_lorenz-sbml.omex",
        "file": "http://127.0.0.1:8001/media/archives/L1V3_lorenz-sbml.omex",
        "created": "2017-11-07T14:07:31.339715Z",
        "md5": "82333b80536f6a75b0370c3cdd2e75f3",
        "task_id": "",
        "tags": [
            "http://127.0.0.1:8001/api/tags/f3f0af48-fa67-44db-861a-9deb9c67c61e/",
            "http://127.0.0.1:8001/api/tags/8503b4dd-43ce-4cee-a0bd-fbf5df89bf0d/",
            "http://127.0.0.1:8001/api/tags/29dfeddc-59f3-4df2-b4b7-4962385cd7ad/"
        ],
        "uuid": "cace90ca-10c7-4ebc-a5e0-5fff85a618fc"
    },
    {
        "name": "L1V3_oscli-nested-pulse.omex",
        "file": "http://127.0.0.1:8001/media/archives/L1V3_oscli-nested-pulse.omex",
        "created": "2017-11-07T14:07:31.381868Z",
        "md5": "481583e8587eaf315e20a4209e767326",
        "task_id": "",
        "tags": [
            "http://127.0.0.1:8001/api/tags/f3f0af48-fa67-44db-861a-9deb9c67c61e/",
            "http://127.0.0.1:8001/api/tags/8503b4dd-43ce-4cee-a0bd-fbf5df89bf0d/",
            "http://127.0.0.1:8001/api/tags/36b8842e-b93d-411d-890c-882e9ef7272e/"
        ],
        "uuid": "025de7cc-4234-4bb4-be72-6bc6e4abc8ac"
    },
    {
        "name": "L1V3_parameter-scan-2d.omex",
        "file": "http://127.0.0.1:8001/media/archives/L1V3_parameter-scan-2d.omex",
        "created": "2017-11-07T14:07:31.415872Z",
        "md5": "bf51abf298c6429ac95b6fccf9baca34",
        "task_id": "",
        "tags": [
            "http://127.0.0.1:8001/api/tags/f3f0af48-fa67-44db-861a-9deb9c67c61e/",
            "http://127.0.0.1:8001/api/tags/8503b4dd-43ce-4cee-a0bd-fbf5df89bf0d/",
            "http://127.0.0.1:8001/api/tags/36b8842e-b93d-411d-890c-882e9ef7272e/"
        ],
        "uuid": "74955e44-58ae-4d27-aa25-5c90d64316f8"
    },
    {
        "name": "L1V3_plotting-data-csv.omex",
        "file": "http://127.0.0.1:8001/media/archives/L1V3_plotting-data-csv.omex",
        "created": "2017-11-07T14:07:31.449382Z",
        "md5": "070377b5983257f546a098251714407e",
        "task_id": "",
        "tags": [
            "http://127.0.0.1:8001/api/tags/f3f0af48-fa67-44db-861a-9deb9c67c61e/",
            "http://127.0.0.1:8001/api/tags/8503b4dd-43ce-4cee-a0bd-fbf5df89bf0d/",
            "http://127.0.0.1:8001/api/tags/36b8842e-b93d-411d-890c-882e9ef7272e/",
            "http://127.0.0.1:8001/api/tags/dcfc26d5-4a65-412b-9988-59066061252a/"
        ],
        "uuid": "31eba525-76e0-4e27-9dc1-89bafa1de501"
    },
    {
        "name": "L1V3_plotting-data-numl.omex",
        "file": "http://127.0.0.1:8001/media/archives/L1V3_plotting-data-numl.omex",
        "created": "2017-11-07T14:07:31.498512Z",
        "md5": "e7001c63fbabd9886dfbe25fcf2f7a58",
        "task_id": "",
        "tags": [
            "http://127.0.0.1:8001/api/tags/f3f0af48-fa67-44db-861a-9deb9c67c61e/",
            "http://127.0.0.1:8001/api/tags/8503b4dd-43ce-4cee-a0bd-fbf5df89bf0d/",
            "http://127.0.0.1:8001/api/tags/36b8842e-b93d-411d-890c-882e9ef7272e/",
            "http://127.0.0.1:8001/api/tags/dcfc26d5-4a65-412b-9988-59066061252a/"
        ],
        "uuid": "d6db7582-ab94-4e8e-8d16-5fd04186c596"
    },
    {
        "name": "L1V3_repeated-scan-oscli.omex",
        "file": "http://127.0.0.1:8001/media/archives/L1V3_repeated-scan-oscli.omex",
        "created": "2017-11-07T14:07:31.540164Z",
        "md5": "0443053bf76ff55261fbc00cc969d03a",
        "task_id": "",
        "tags": [
            "http://127.0.0.1:8001/api/tags/f3f0af48-fa67-44db-861a-9deb9c67c61e/",
            "http://127.0.0.1:8001/api/tags/8503b4dd-43ce-4cee-a0bd-fbf5df89bf0d/",
            "http://127.0.0.1:8001/api/tags/36b8842e-b93d-411d-890c-882e9ef7272e/"
        ],
        "uuid": "181da630-96e7-4c4a-9ad0-6fee07c705bf"
    },
    {
        "name": "L1V3_repeated-steady-scan-oscli.omex",
        "file": "http://127.0.0.1:8001/media/archives/L1V3_repeated-steady-scan-oscli.omex",
        "created": "2017-11-07T14:07:31.572111Z",
        "md5": "f4b5f8e3f443f59f63f0bea0741c03ab",
        "task_id": "",
        "tags": [
            "http://127.0.0.1:8001/api/tags/f3f0af48-fa67-44db-861a-9deb9c67c61e/",
            "http://127.0.0.1:8001/api/tags/8503b4dd-43ce-4cee-a0bd-fbf5df89bf0d/",
            "http://127.0.0.1:8001/api/tags/36b8842e-b93d-411d-890c-882e9ef7272e/"
        ],
        "uuid": "ce0f0f83-abb2-406d-8eca-ac3f348ba121"
    },
    {
        "name": "L1V3_repeated-stochastic-runs.omex",
        "file": "http://127.0.0.1:8001/media/archives/L1V3_repeated-stochastic-runs.omex",
        "created": "2017-11-07T14:07:31.604577Z",
        "md5": "76cc799746b32a7c6d2367bf76c17fad",
        "task_id": "",
        "tags": [
            "http://127.0.0.1:8001/api/tags/f3f0af48-fa67-44db-861a-9deb9c67c61e/",
            "http://127.0.0.1:8001/api/tags/8503b4dd-43ce-4cee-a0bd-fbf5df89bf0d/",
            "http://127.0.0.1:8001/api/tags/36b8842e-b93d-411d-890c-882e9ef7272e/"
        ],
        "uuid": "fb939cde-5824-4639-a0b9-03a6d7bd92c8"
    },
    {
        "name": "L1V3_vanderpol-sbml.omex",
        "file": "http://127.0.0.1:8001/media/archives/L1V3_vanderpol-sbml.omex",
        "created": "2017-11-07T14:07:31.716716Z",
        "md5": "57479e2720cf7f1078697920b4100aed",
        "task_id": "",
        "tags": [
            "http://127.0.0.1:8001/api/tags/f3f0af48-fa67-44db-861a-9deb9c67c61e/",
            "http://127.0.0.1:8001/api/tags/8503b4dd-43ce-4cee-a0bd-fbf5df89bf0d/",
            "http://127.0.0.1:8001/api/tags/36b8842e-b93d-411d-890c-882e9ef7272e/"
        ],
        "uuid": "c41bf5a6-21cb-48d6-a00c-cd4a20c8b636"
    }
]

In [129]:
data = client.action(document,["tags", "list"], params={"type":"format"} )
print(json.dumps(data,indent=4))


[
    {
        "name": "sbml",
        "type": "format",
        "uuid": "f3f0af48-fa67-44db-861a-9deb9c67c61e"
    },
    {
        "name": "cellml",
        "type": "format",
        "uuid": "59dafcf2-82c0-4f48-bb4d-3954cacc2b47"
    },
    {
        "name": "sbgn",
        "type": "format",
        "uuid": "74afbb79-9ba9-4795-9677-0fbfe017ab51"
    },
    {
        "name": "sed-ml",
        "type": "format",
        "uuid": "8503b4dd-43ce-4cee-a0bd-fbf5df89bf0d"
    }
]

In [141]:
data = client.action(document,["users", "list",], params={"search":"ja"} )
print(json.dumps(data,indent=4))


[
    {
        "url": "http://127.0.0.1:8001/api/users/1/",
        "username": "janek89",
        "email": "janekg89@hotmail.de",
        "is_staff": true
    }
]

In [ ]: