Skip to content

Commit 461c261

Browse files
committed
Api keys content
1 parent 986c4dc commit 461c261

File tree

1 file changed

+48
-3
lines changed

1 file changed

+48
-3
lines changed

tutorial/api_keys.rst

+48-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,52 @@
11
API Keys
22
========
33

4-
To Do:
4+
How to get an API Key
5+
---------------------
56

6-
* How to create an API Key
7-
* How to use the API Key in the SDK
7+
Your personal API Key is generated in the SimScale platform. Follow these steps:
8+
9+
1. Sign in to the SimScale platform in `www.simscale.com <https://www.simscale.com/>`_
10+
2. Open account menu at the top left
11+
3. Go to 'Manage Account' or 'User Preferences', depending on wether you are in the Workbench
12+
4. Open the 'API Keys' tab
13+
5. Use the 'Generate Key' button
14+
6. Enter a description for this new key
15+
7. Copy the key to a safe location, for instance to your ``.env`` file
16+
17+
If doing so, your ``.env`` file should contain a line such as:
18+
19+
.. code-block:: python
20+
21+
SIMSCALE_API_KEY=(generated api key)
22+
23+
24+
API Client
25+
----------
26+
27+
User authentication with the SimScale API is performed using the ``X-API-KEY`` request header.
28+
In your code, you must first initialize and configure a ``simscale_sdk.ApiClient`` object, which
29+
holds the data for the host, identification header and API Key. This object is later used to
30+
setup the different Api clients specific to each platform action.
31+
32+
The following snippet shows an example of the creation and setup of the ``ApiClient`` object:
33+
34+
.. code-block:: python
35+
36+
import os
37+
from dotenv import load_dotenv()
38+
39+
import simscale_sdk as sim
40+
41+
load_dotenv()
42+
43+
API_KEY = os.getenv('SIMSCALE_API_KEY')
44+
API_HOST_URL = "https://api.simscale.com/v0"
45+
46+
configuration = sim.Configuration()
47+
configuration.host = API_HOST_URL
48+
configuration.api_key = {
49+
"X-API-KEY": API_KEY
50+
}
51+
52+
api_client = sim.ApiClient(configuration)

0 commit comments

Comments
 (0)