-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
406 additions
and
365 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
224 changes: 224 additions & 0 deletions
224
nbs/docs/getting-started/2_setting_up_your_authentication_token.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,224 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Setting Up Your Authentication Token " | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"A **token**, also known as an **API Key**, is a unique string of characters that serves as a key to authenticate your requests to `TimeGTP`. This tutorial will explain how to set up your token when using the Nixtla SDK. \n", | ||
"\n", | ||
"Upon [registration](https://dashboard.nixtla.io/), you will recibe an email asking you to confirm your signup. After confirming, you will receive access to your dashboard. There, under `API Keys`, you will find your token. To integrate your token into your development workflow with the Nixtla SDK, you have two methods. " | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## 1. Direct copy and paste \n", | ||
"\n", | ||
"- **Step 1**: Copy the token found in the `API Keys` of your [dashboard]((https://dashboard.nixtla.io/)). \n", | ||
"- **Step 2**: Instantiate the `TimeGPT` class by directly pasting your token into the code, as shown below:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from nixtlats import TimeGPT \n", | ||
"timegpt = TimeGPT(token = 'your token here')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"This approach is straightforward and best for quick tests or scripts that won’t be shared." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## 2. Using an environment variable" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"- **Step 1:** Store your token in an environment variable named `TIMEGPT_TOKEN`. This can be done for a session or permanently, depending on your preference.\n", | ||
"- **Step 2:** When you instantiate the `TimeGPT` class, the SDK will automatically look for the `TIMEGPT_TOKEN` environment variable and use it to authenticate your requests." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"True" | ||
] | ||
}, | ||
"execution_count": null, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"#| hide\n", | ||
"from dotenv import load_dotenv\n", | ||
"load_dotenv()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from nixtlats import TimeGPT\n", | ||
"timegpt = TimeGPT()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"::: {.callout-important}\n", | ||
"The environment variable must be named exactly `TIMEGPT_TOKEN`, with all capital letters and no deviations in spelling, for the SDK to recognize it.\n", | ||
"::: " | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"There are several ways to set an environment variable. " | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### a. From the Terminal\n", | ||
"Use the `export` command to set `TIMEGPT_TOKEN`. \n", | ||
"\n", | ||
"``` bash\n", | ||
"export TIMEGPT_TOKEN=your_token\n", | ||
"```" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### b. Using a `.env` file\n", | ||
"\n", | ||
"For a more persistent solution that can be version-controlled if private, or for ease of use across different projects, place your token in a `.env` file.\n", | ||
"\n", | ||
"``` bash\n", | ||
"# Inside a file named .env\n", | ||
"TIMEGPT_TOKEN=your_token\n", | ||
"```" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"**Within Python:** If using a `.env` file, you can load the environment variable within your Python script. Use the `dotenv` package to load the `.env` file and then instantiate the `TimeGPT` class." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from dotenv import load_dotenv\n", | ||
"load_dotenv()\n", | ||
"\n", | ||
"from nixtlats import TimeGPT\n", | ||
"timegpt = TimeGPT()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"This approach is more secure and suitable for applications that will be deployed or shared, as it keeps tokens out of the source code." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"::: {.callout-important}\n", | ||
"Remember, your token is like a password - keep it secret, keep it safe!\n", | ||
"::: " | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Validate your token\n", | ||
"\n", | ||
"You can always find your token in the `API Keys` section of your dashboard. To check the status of your token, use the [`validate_token` method](https://nixtlaverse.nixtla.io/nixtla/timegpt.html#timegpt-validate-token) of the `TimeGPT` class. This method will return `True` if the token is valid and `False` otherwise. " | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stderr", | ||
"output_type": "stream", | ||
"text": [ | ||
"INFO:nixtlats.timegpt:Happy Forecasting! :), If you have questions or need support, please email [email protected]\n" | ||
] | ||
}, | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"True" | ||
] | ||
}, | ||
"execution_count": null, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"timegpt.validate_token()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"You don't need to validate your token every time you use `TimeGPT`. This function is provided for your convenience to ensure its validity. For full access to `TimeGPT`'s functionalities, in addition to a valid token, you also need sufficient credits in your account. You can check your credits in the `Usage` section of your [dashboard]((https://dashboard.nixtla.io/)). " | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "python3", | ||
"language": "python", | ||
"name": "python3" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
Oops, something went wrong.