Skip to content

Examples

Basic

Initiate API client and fetch all available campaigns.

1
2
3
4
5
6
7
8
"""
Basic example showing how to initiate the client and list available model test campaigns.
"""
from modeltestsdk import Client


client = Client()
campaigns = client.campaign.get()

Note

the get_all() method was previously used to return several results

Create campaign

Add a campaign to the database, using datetime to properly handle the date.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
"""
Simple create example
"""
from datetime import datetime
from modeltestsdk import Client

client = Client()
campaign = client.campaign.create(name="Campaign name",
                                  description="Campaign description",
                                  date=datetime(year=2000, month=1, day=1).isoformat(),
                                  location="Test location",
                                  scale_factor=52,
                                  water_depth=300,
                                  read_only=True)

Get campaign

This example will filter by campaign name and description and sort ascending by date. The filter object enables use of Pythonic syntax

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
"""
Simple example using the sort and filter objects
"""
from modeltestsdk import Client
client = Client()

campaigns = client.campaign.get(filter_by=[
     client.filter.campaign.name == "Campaign name",
     client.filter.campaign.description == "Campaign description"],
     sort_by=[client.sort.campaign.date.asc])

Note

Filtering and sort arguments needs to be contained inside a list. Sorting will be done in the order the arguments are given in the list

Note

the get_all() method was previously used to return several results