captn-client


Namecaptn-client JSON
Version 2023.3.0 PyPI version JSON
download
home_pagehttps://github.com/airtai/captn-client
SummaryCaptn client library
upload_time2023-03-31 12:13:20
maintainer
docs_urlNone
authorairt.ai
requires_python>=3.7
licenseCreative Commons License
keywords nbdev jupyter notebook python airt captn keras tensorflow ml ai
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Capt’n python client
================

<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

## Docs

For full documentation, Please follow the below link:

- <a href="https://docs.captn.ai" target="_blank">https://docs.captn.ai/</a>

## How to install

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

``` console
pip install captn-client
```

## How to use

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

- <https://bit.ly/3I4cNuv>

After successful verification, you will receive an email with the
username and password for the developer account.

Once you have the credentials, use them to get an access token by
calling `Client.get_token` method. It is necessary to get an access
token; otherwise, you won’t be able to access all of the captn service’s
APIs. You can either pass the username, password, and server address as
parameters to the `Client.get_token` method or store them in the
environment variables **CAPTN_SERVICE_USERNAME**,
**CAPTN_SERVICE_PASSWORD**, and **CAPTN_SERVER_URL**.

In addition to the regular authentication with credentials, you can also
enable multi-factor authentication (MFA) and single sign-on (SSO) for
generating tokens.

To help protect your account, we recommend that you enable multi-factor
authentication (MFA). MFA provides additional security by requiring you
to provide unique verification code (OTP) in addition to your regular
sign-in credentials when performing critical operations.

Your account can be configured for MFA in just two easy steps:

1.  To begin, you need to enable MFA for your account by calling the
    `User.enable_mfa` method, which will generate a QR code. You can
    then scan the QR code with an authenticator app, such as Google
    Authenticator and follow the on-device instructions to finish the
    setup in your smartphone.

2.  Finally, activate MFA for your account by calling
    `User.activate_mfa` and passing the dynamically generated six-digit
    verification code from your smartphone’s authenticator app.

You can also disable MFA for your account at any time by calling the
method `User.disable_mfa` method.

Single sign-on (SSO) can be enabled for your account in three simple
steps:

1.  Enable the SSO for a provider by calling the `User.enable_sso`
    method with the SSO provider name and an email address. At the
    moment, we only support “google” and “github” as SSO providers. We
    intend to support additional SSO providers in future releases.

2.  Before you can start generating new tokens with SSO, you must first
    authenticate with the SSO provider. Call the `Client.get_token` with
    the same SSO provider you have enabled in the step above to generate
    an SSO authorization URL. Please copy and paste it into your
    preferred browser and complete the authentication process with the
    SSO provider.

3.  After successfully authenticating with the SSO provider, call the
    `Client.set_sso_token` method to generate a new token and use it
    automatically in all future interactions with the captn server.

For more information, please check:

- [Tutorial](https://docs.captn.ai/Tutorial/) with more elaborate
  example, and

- [API](https://docs.captn.ai/API/client/Client/) with reference
  documentation.

Here’s a minimal example showing how to use captn services to train a
model and make predictions.

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

``` python
# Importing necessary libraries
from captn.client import Client, DataBlob, DataSource

# Authenticate
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.

``` python
# Before you can use the data to train a model, it must be uploaded to the
# captn server. Run the following command to upload the data to the
# captn server for further processing.
data_blob = DataBlob.from_s3(uri="s3://test-airt-service/sample_gaming_130k")

# Display the upload progress
data_blob.progress_bar()
```

    100%|██████████| 1/1 [00:35<00:00, 35.44s/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:

``` python
# Add header rows
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.to_datasource`
method which preprocesses the data and stores it in captn server.

``` python
# Preprocess and prepare the data for training
data_source = data_blob.to_datasource(
    file_type="csv", index_column="game_name", sort_by="date", **kwargs
)

# Display the data preprocessing progress
data_source.progress_bar()
```

    100%|██████████| 1/1 [00:55<00:00, 55.66s/it]

``` python
# When the preprocessing is finished, you can run the following command to
# display the head of the data to ensure everything is fine.
print(data_source.head())
```

                      date platform          user_type            network  \
    game_name                                                               
    game_name_0 2021-03-15      ios      jetfuelit_int      jetfuelit_int   
    game_name_0 2021-03-15      ios      jetfuelit_int      jetfuelit_int   
    game_name_0 2021-03-15      ios      jetfuelit_int      jetfuelit_int   
    game_name_0 2021-03-15      ios      jetfuelit_int      jetfuelit_int   
    game_name_0 2021-03-15      ios      jetfuelit_int      jetfuelit_int   
    game_name_0 2021-03-15  android  googleadwords_int  googleadwords_int   
    game_name_0 2021-03-15  android  googleadwords_int  googleadwords_int   
    game_name_0 2021-03-15  android         moloco_int         moloco_int   
    game_name_0 2021-03-15  android      jetfuelit_int      jetfuelit_int   
    game_name_0 2021-03-15  android      jetfuelit_int      jetfuelit_int   

                     campaign       adgroup  installs       spend  revenue_0  \
    game_name                                                                  
    game_name_0    campaign_0   adgroup_541         1    0.600000   0.000000   
    game_name_0    campaign_0  adgroup_2351         2    4.900000   0.000000   
    game_name_0    campaign_0   adgroup_636         3    7.350000   0.000000   
    game_name_0    campaign_0   adgroup_569         1    0.750000   0.000000   
    game_name_0    campaign_0   adgroup_243         2    3.440000   0.000000   
    game_name_0  campaign_283  adgroup_1685        11    0.000000   0.000000   
    game_name_0    campaign_2    adgroup_56        32   30.090000   0.000000   
    game_name_0  campaign_191          None       291  503.480011  34.701553   
    game_name_0    campaign_0   adgroup_190         4    2.740000   0.000000   
    game_name_0    campaign_0   adgroup_755         8   11.300000  13.976003   

                 revenue_1  ...  revenue_23  revenue_24  revenue_25  revenue_26  \
    game_name               ...                                                   
    game_name_0   0.018173  ...    0.018173    0.018173    0.018173    0.018173   
    game_name_0   0.034000  ...    0.034000    6.034000    6.034000    6.034000   
    game_name_0   0.000000  ...   12.112897   12.112897   12.112897   12.112897   
    game_name_0   0.029673  ...    0.029673    0.029673    0.029673    0.029673   
    game_name_0   0.027981  ...    0.042155    0.042155    0.042155    0.042155   
    game_name_0   0.097342  ...    0.139581    0.139581    0.139581    0.139581   
    game_name_0   0.802349  ...    2.548253    2.548253    2.771138    2.805776   
    game_name_0  63.618111  ...  116.508331  117.334709  117.387489  117.509506   
    game_name_0   0.000000  ...    0.000000    0.000000    0.000000    0.000000   
    game_name_0  14.358793  ...   14.338905   14.338905   14.338905   14.338905   

                 revenue_27  revenue_28  revenue_29  revenue_30  revenue_60  \
    game_name                                                                 
    game_name_0    0.018173    0.018173    0.018173    0.018173    0.018173   
    game_name_0    6.034000    6.034000    6.034000    6.034000    6.034000   
    game_name_0   12.112897   12.112897   12.112897   12.112897   12.112897   
    game_name_0    0.029673    0.029673    0.029673    0.029673    0.029673   
    game_name_0    0.042155    0.042155    0.042155    0.042155    0.042155   
    game_name_0    0.139581    0.139581    0.139581    0.139581    0.139581   
    game_name_0    2.805776    2.805776    2.805776    2.805776    2.805776   
    game_name_0  118.811417  118.760765  119.151291  119.350220  139.069443   
    game_name_0    0.000000    0.000000    0.000000    0.000000    0.000000   
    game_name_0   14.338905   14.338905   14.338905   14.338905   14.338905   

                 revenue_90  
    game_name                
    game_name_0    0.018173  
    game_name_0   13.030497  
    game_name_0   12.112897  
    game_name_0    0.029673  
    game_name_0    0.042155  
    game_name_0    0.139581  
    game_name_0    2.805776  
    game_name_0  147.528793  
    game_name_0    0.000000  
    game_name_0   14.338905  

    [10 rows x 41 columns]

### 2. Training

``` python
# Todo
```



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/airtai/captn-client",
    "name": "captn-client",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "nbdev jupyter notebook python airt captn keras tensorflow ML AI",
    "author": "airt.ai",
    "author_email": "info@airt.ai",
    "download_url": "https://files.pythonhosted.org/packages/f2/cc/d41649c2e4230455bfecf5340e6f1f3df1cf9b270eecffa652b0d23b61f3/captn-client-2023.3.0.tar.gz",
    "platform": null,
    "description": "Capt\u2019n python client\n================\n\n<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->\n\n## Docs\n\nFor full documentation, Please follow the below link:\n\n- <a href=\"https://docs.captn.ai\" target=\"_blank\">https://docs.captn.ai/</a>\n\n## How to install\n\nIf you don\u2019t have the captn library already installed, please install it\nusing pip.\n\n``` console\npip install captn-client\n```\n\n## How to use\n\nTo access the captn service, you must first create a developer account.\nPlease fill out the signup form below to get one:\n\n- <https://bit.ly/3I4cNuv>\n\nAfter successful verification, you will receive an email with the\nusername and password for the developer account.\n\nOnce you have the credentials, use them to get an access token by\ncalling `Client.get_token` method. It is necessary to get an access\ntoken; otherwise, you won\u2019t be able to access all of the captn service\u2019s\nAPIs. You can either pass the username, password, and server address as\nparameters to the `Client.get_token` method or store them in the\nenvironment variables **CAPTN_SERVICE_USERNAME**,\n**CAPTN_SERVICE_PASSWORD**, and **CAPTN_SERVER_URL**.\n\nIn addition to the regular authentication with credentials, you can also\nenable multi-factor authentication (MFA) and single sign-on (SSO) for\ngenerating tokens.\n\nTo help protect your account, we recommend that you enable multi-factor\nauthentication (MFA). MFA provides additional security by requiring you\nto provide unique verification code (OTP) in addition to your regular\nsign-in credentials when performing critical operations.\n\nYour account can be configured for MFA in just two easy steps:\n\n1.  To begin, you need to enable MFA for your account by calling the\n    `User.enable_mfa` method, which will generate a QR code. You can\n    then scan the QR code with an authenticator app, such as Google\n    Authenticator and follow the on-device instructions to finish the\n    setup in your smartphone.\n\n2.  Finally, activate MFA for your account by calling\n    `User.activate_mfa` and passing the dynamically generated six-digit\n    verification code from your smartphone\u2019s authenticator app.\n\nYou can also disable MFA for your account at any time by calling the\nmethod `User.disable_mfa` method.\n\nSingle sign-on (SSO) can be enabled for your account in three simple\nsteps:\n\n1.  Enable the SSO for a provider by calling the `User.enable_sso`\n    method with the SSO provider name and an email address. At the\n    moment, we only support \u201cgoogle\u201d and \u201cgithub\u201d as SSO providers. We\n    intend to support additional SSO providers in future releases.\n\n2.  Before you can start generating new tokens with SSO, you must first\n    authenticate with the SSO provider. Call the `Client.get_token` with\n    the same SSO provider you have enabled in the step above to generate\n    an SSO authorization URL. Please copy and paste it into your\n    preferred browser and complete the authentication process with the\n    SSO provider.\n\n3.  After successfully authenticating with the SSO provider, call the\n    `Client.set_sso_token` method to generate a new token and use it\n    automatically in all future interactions with the captn server.\n\nFor more information, please check:\n\n- [Tutorial](https://docs.captn.ai/Tutorial/) with more elaborate\n  example, and\n\n- [API](https://docs.captn.ai/API/client/Client/) with reference\n  documentation.\n\nHere\u2019s a minimal example showing how to use captn services to train a\nmodel and make predictions.\n\nIn the below example, the username, password, and server address are\nstored in **CAPTN_SERVICE_USERNAME**, **CAPTN_SERVICE_PASSWORD**, and\n**CAPTN_SERVER_URL** environment variables.\n\n### 0. Get token\n\n``` python\n# Importing necessary libraries\nfrom captn.client import Client, DataBlob, DataSource\n\n# Authenticate\nClient.get_token()\n```\n\n### 1. Connect and preprocess data\n\nIn our example, we will be using the captn APIs to load and preprocess a\nsample CSV file stored in an AWS S3 bucket.\n\n``` python\n# Before you can use the data to train a model, it must be uploaded to the\n# captn server. Run the following command to upload the data to the\n# captn server for further processing.\ndata_blob = DataBlob.from_s3(uri=\"s3://test-airt-service/sample_gaming_130k\")\n\n# Display the upload progress\ndata_blob.progress_bar()\n```\n\n    100%|\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588| 1/1 [00:35<00:00, 35.44s/it]\n\nThe sample data we used in this example doesn\u2019t have the header rows and\ntheir data types defined.\n\nThe following code creates the necessary headers along with their data\ntypes and reads only a subset of columns that are required for modeling:\n\n``` python\n# Add header rows\nprefix = [\"revenue\", \"ad_revenue\", \"conversion\", \"retention\"]\ndays = list(range(30)) + list(range(30, 361, 30))\ndtype = {\n    \"date\": \"str\",\n    \"game_name\": \"str\",\n    \"platform\": \"str\",\n    \"user_type\": \"str\",\n    \"network\": \"str\",\n    \"campaign\": \"str\",\n    \"adgroup\": \"str\",\n    \"installs\": \"int32\",\n    \"spend\": \"float32\",\n}\ndtype.update({f\"{p}_{d}\": \"float32\" for p in prefix for d in days})\nnames = list(dtype.keys())\n\nkwargs = {\n    \"delimiter\": \"|\",\n    \"names\": names,\n    \"parse_dates\": [\"date\"],\n    \"usecols\": names[:42],\n    \"dtype\": dtype,\n}\n```\n\nFinally, the above variables are passed to the `DataBlob.to_datasource`\nmethod which preprocesses the data and stores it in captn server.\n\n``` python\n# Preprocess and prepare the data for training\ndata_source = data_blob.to_datasource(\n    file_type=\"csv\", index_column=\"game_name\", sort_by=\"date\", **kwargs\n)\n\n# Display the data preprocessing progress\ndata_source.progress_bar()\n```\n\n    100%|\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588| 1/1 [00:55<00:00, 55.66s/it]\n\n``` python\n# When the preprocessing is finished, you can run the following command to\n# display the head of the data to ensure everything is fine.\nprint(data_source.head())\n```\n\n                      date platform          user_type            network  \\\n    game_name                                                               \n    game_name_0 2021-03-15      ios      jetfuelit_int      jetfuelit_int   \n    game_name_0 2021-03-15      ios      jetfuelit_int      jetfuelit_int   \n    game_name_0 2021-03-15      ios      jetfuelit_int      jetfuelit_int   \n    game_name_0 2021-03-15      ios      jetfuelit_int      jetfuelit_int   \n    game_name_0 2021-03-15      ios      jetfuelit_int      jetfuelit_int   \n    game_name_0 2021-03-15  android  googleadwords_int  googleadwords_int   \n    game_name_0 2021-03-15  android  googleadwords_int  googleadwords_int   \n    game_name_0 2021-03-15  android         moloco_int         moloco_int   \n    game_name_0 2021-03-15  android      jetfuelit_int      jetfuelit_int   \n    game_name_0 2021-03-15  android      jetfuelit_int      jetfuelit_int   \n\n                     campaign       adgroup  installs       spend  revenue_0  \\\n    game_name                                                                  \n    game_name_0    campaign_0   adgroup_541         1    0.600000   0.000000   \n    game_name_0    campaign_0  adgroup_2351         2    4.900000   0.000000   \n    game_name_0    campaign_0   adgroup_636         3    7.350000   0.000000   \n    game_name_0    campaign_0   adgroup_569         1    0.750000   0.000000   \n    game_name_0    campaign_0   adgroup_243         2    3.440000   0.000000   \n    game_name_0  campaign_283  adgroup_1685        11    0.000000   0.000000   \n    game_name_0    campaign_2    adgroup_56        32   30.090000   0.000000   \n    game_name_0  campaign_191          None       291  503.480011  34.701553   \n    game_name_0    campaign_0   adgroup_190         4    2.740000   0.000000   \n    game_name_0    campaign_0   adgroup_755         8   11.300000  13.976003   \n\n                 revenue_1  ...  revenue_23  revenue_24  revenue_25  revenue_26  \\\n    game_name               ...                                                   \n    game_name_0   0.018173  ...    0.018173    0.018173    0.018173    0.018173   \n    game_name_0   0.034000  ...    0.034000    6.034000    6.034000    6.034000   \n    game_name_0   0.000000  ...   12.112897   12.112897   12.112897   12.112897   \n    game_name_0   0.029673  ...    0.029673    0.029673    0.029673    0.029673   \n    game_name_0   0.027981  ...    0.042155    0.042155    0.042155    0.042155   \n    game_name_0   0.097342  ...    0.139581    0.139581    0.139581    0.139581   \n    game_name_0   0.802349  ...    2.548253    2.548253    2.771138    2.805776   \n    game_name_0  63.618111  ...  116.508331  117.334709  117.387489  117.509506   \n    game_name_0   0.000000  ...    0.000000    0.000000    0.000000    0.000000   \n    game_name_0  14.358793  ...   14.338905   14.338905   14.338905   14.338905   \n\n                 revenue_27  revenue_28  revenue_29  revenue_30  revenue_60  \\\n    game_name                                                                 \n    game_name_0    0.018173    0.018173    0.018173    0.018173    0.018173   \n    game_name_0    6.034000    6.034000    6.034000    6.034000    6.034000   \n    game_name_0   12.112897   12.112897   12.112897   12.112897   12.112897   \n    game_name_0    0.029673    0.029673    0.029673    0.029673    0.029673   \n    game_name_0    0.042155    0.042155    0.042155    0.042155    0.042155   \n    game_name_0    0.139581    0.139581    0.139581    0.139581    0.139581   \n    game_name_0    2.805776    2.805776    2.805776    2.805776    2.805776   \n    game_name_0  118.811417  118.760765  119.151291  119.350220  139.069443   \n    game_name_0    0.000000    0.000000    0.000000    0.000000    0.000000   \n    game_name_0   14.338905   14.338905   14.338905   14.338905   14.338905   \n\n                 revenue_90  \n    game_name                \n    game_name_0    0.018173  \n    game_name_0   13.030497  \n    game_name_0   12.112897  \n    game_name_0    0.029673  \n    game_name_0    0.042155  \n    game_name_0    0.139581  \n    game_name_0    2.805776  \n    game_name_0  147.528793  \n    game_name_0    0.000000  \n    game_name_0   14.338905  \n\n    [10 rows x 41 columns]\n\n### 2. Training\n\n``` python\n# Todo\n```\n\n\n",
    "bugtrack_url": null,
    "license": "Creative Commons License",
    "summary": "Captn client library",
    "version": "2023.3.0",
    "split_keywords": [
        "nbdev",
        "jupyter",
        "notebook",
        "python",
        "airt",
        "captn",
        "keras",
        "tensorflow",
        "ml",
        "ai"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1a5343d6c5b2b0391a657494dd05bbe915a1810fd039a194c5cd8573daf50fa2",
                "md5": "9da2a602175a3f5be3dd1d07452fdae0",
                "sha256": "6b63bc6e1c44d67132767bf2d50b0c255bffa1d2a627f459886eb02f528faffd"
            },
            "downloads": -1,
            "filename": "captn_client-2023.3.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9da2a602175a3f5be3dd1d07452fdae0",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 14287,
            "upload_time": "2023-03-31T12:13:18",
            "upload_time_iso_8601": "2023-03-31T12:13:18.911393Z",
            "url": "https://files.pythonhosted.org/packages/1a/53/43d6c5b2b0391a657494dd05bbe915a1810fd039a194c5cd8573daf50fa2/captn_client-2023.3.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f2ccd41649c2e4230455bfecf5340e6f1f3df1cf9b270eecffa652b0d23b61f3",
                "md5": "b2df842ba73536b637ec619f525fd22d",
                "sha256": "bceda8123e421e61ca80c717062eab4a2da2f9d9a4f6e32e6d14034bcbc86682"
            },
            "downloads": -1,
            "filename": "captn-client-2023.3.0.tar.gz",
            "has_sig": false,
            "md5_digest": "b2df842ba73536b637ec619f525fd22d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 17000,
            "upload_time": "2023-03-31T12:13:20",
            "upload_time_iso_8601": "2023-03-31T12:13:20.815493Z",
            "url": "https://files.pythonhosted.org/packages/f2/cc/d41649c2e4230455bfecf5340e6f1f3df1cf9b270eecffa652b0d23b61f3/captn-client-2023.3.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-03-31 12:13:20",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "airtai",
    "github_project": "captn-client",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "captn-client"
}
        
Elapsed time: 0.05667s