Skip to main content

Capt’n client

Project description

Capt’n python client 2022.3.0rc1

A python library encapsulating captn service REST API available at:

Docs

Full documentation can be found at the following link:

How to install

If you don't have the captn library already installed, please install it using pip.

pip install captn-client

How to use

To access the captn service, you must create a developer account. Please fill out the signup form below to get one:

Upon successful verification, you will receive the username/password for the developer account in an email.

Finally, you need an application token to access all the APIs in captn service. Please call the Client.get_token method with the username/password to get one.

You can either pass the username, password, and server address as parameters to the Client.get_token method or store the same in the CAPTN_SERVICE_USERNAME, CAPTN_SERVICE_PASSWORD, and CAPTN_SERVER_URL environment variables.

After successful authentication, the captn services will be available to access.

For more information, please check:

  • Tutorial with more elaborate example, and

  • API with reference documentation.

Below is a minimal example explaining how to load the data, train a model and make predictions using captn services.

!!! info

In the below example, the username, password, and server address are stored in **CAPTN_SERVICE_USERNAME**, **CAPTN_SERVICE_PASSWORD**, and **CAPTN_SERVER_URL** environment variables.

0. Get token

import json
from captn.client import Client, DataBlob, DataSource

Client.get_token()

1. Connect and preprocess data

In our example, we will be using the captn APIs to load and preprocess a sample CSV file stored in an AWS S3 bucket.

data_blob = DataBlob.from_s3(
    uri="s3://test-airt-service/sample_gaming_cohort_data/"
)
data_blob.progress_bar()

100%|██████████| 1/1 [01:35<00:00, 95.81s/it]

The sample data we used in this example doesn't have the header rows and their data types defined.

The following code creates the necessary headers along with their data types and reads only a subset of columns that are required for modeling:

prefix = ["revenue", "ad_revenue", "conversion", "retention"]
days = list(range(30)) + list(range(30, 361, 30))
dtype = {
    "date": "str",
    "game_name": "str",
    "platform": "str",
    "user_type": "str",
    "network": "str",
    "campaign": "str",
    "adgroup": "str",
    "installs": "int32",
    "spend": "float32",
}
dtype.update({f"{p}_{d}": "float32" for p in prefix for d in days})
names = list(dtype.keys())

kwargs = {"delimiter": "|", "names": names, "parse_dates": ["date"], "usecols": names[:42], "dtype": dtype}

Finally, the above variables are passed to the DataBlob.from_csv method which preprocesses the data and stores it in captn server.

data_source = data_blob.from_csv(
    index_column="game_name",
    sort_by="date",
    kwargs_json=json.dumps(kwargs)
)

data_source.progress_bar()
100%|██████████| 1/1 [00:40<00:00, 40.37s/it]
data_source.head()
<style scoped> .dataframe tbody tr th:only-of-type { vertical-align: middle; }
.dataframe tbody tr th {
    vertical-align: top;
}

.dataframe thead th {
    text-align: right;
}
</style>
date platform user_type network campaign adgroup installs spend revenue_0 revenue_1 ... revenue_23 revenue_24 revenue_25 revenue_26 revenue_27 revenue_28 revenue_29 revenue_30 revenue_60 revenue_90
0 2021-03-15 ios Facebook Ads Facebook Ads campaign_144 adgroup_271 96 545.849976 130.000000 170.144928 ... 632.002380 632.539246 660.857056 666.857056 666.857056 700.857056 729.035645 729.035645 1115.538574 1282.981079
1 2021-03-15 ios snapchat_int snapchat_int campaign_569 adgroup_1634 10 207.919998 33.000000 39.000000 ... 71.282143 71.282143 71.282143 71.282143 73.376190 73.376190 73.376190 73.376190 94.752373 143.727859
2 2021-03-15 ios unityads_int unityads_int campaign_62 adgroup_275 41 73.339996 6.000000 22.297548 ... 42.324429 42.462334 42.462334 42.462334 42.500793 43.640785 43.869404 43.871078 50.590389 50.590389
3 2021-03-15 ios jetfuelit_int jetfuelit_int campaign_0 adgroup_683 32 60.099998 33.000000 45.928074 ... 58.466618 58.466618 58.466618 58.466618 58.466618 58.466618 58.466618 58.466618 58.466618 72.491997
4 2021-03-15 ios jetfuelit_int jetfuelit_int campaign_0 adgroup_278 9 19.500000 13.000000 13.438093 ... 19.427818 19.427818 19.427818 19.427818 19.427818 19.427818 19.427818 19.427818 19.427818 19.427818
5 2021-03-15 ios jetfuelit_int jetfuelit_int campaign_0 adgroup_921 4 7.950000 0.000000 0.129259 ... 4.205401 4.205401 4.205401 4.205401 4.205401 4.205401 4.205401 4.205401 4.227401 4.227401
6 2021-03-15 ios jetfuelit_int jetfuelit_int campaign_0 adgroup_327 3 5.380000 0.000000 0.000000 ... 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
7 2021-03-15 ios jetfuelit_int jetfuelit_int campaign_0 adgroup_5815 1 2.450000 0.000000 0.000000 ... 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
8 2021-03-15 ios jetfuelit_int jetfuelit_int campaign_0 adgroup_162 1 0.600000 0.000000 0.026555 ... 0.026555 0.026555 0.026555 0.026555 0.026555 0.026555 0.026555 0.026555 0.026555 0.026555
9 2021-03-15 android Facebook Ads Facebook Ads campaign_23 adgroup_9 730 335.640015 36.300461 59.481831 ... 124.508873 124.631615 124.644920 124.652664 124.905174 124.946205 125.000298 125.046783 125.483368 125.519073

10 rows × 41 columns

2. Training

# Todo

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

captn-client-2022.3.0rc1.tar.gz (18.9 kB view hashes)

Uploaded Source

Built Distribution

captn_client-2022.3.0rc1-py3-none-any.whl (17.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page