Initializing a Client
Problem
You want to get started using the Posit SDK by initializing a connection to your server.
Credential information may be supplied inline or at runtime via the following environment variables.
- CONNECT_API_KEY - Your unique Posit Connect API key.
- CONNECT_SERVER - Your Posit Connect server URL.
Solution
Create a Posit Connect client and provide credential information at runtime via environment variables.
Option 1 (Preferred)
Import the connect
module from posit
and create a Client
.
from posit import connect
= connect.Client() client
library(connectapi)
<- connect() client
Option 2
Create a Posit Connect client and define credential information inline.
Keep your credentials safe. Do not use inline credentials if you need to share your program with others. Instead, provide your credentials via environment variables or obtain them through a secrets manager.
from posit import connect
= "https://connect.example.com"
URL = "abcdefghijklmnopqrstuvwxyz123456"
API_KEY
= connect.Client(URL, API_KEY) client
library(connectapi)
= "https://connect.example.com"
URL = "abcdefghijklmnopqrstuvwxyz123456"
API_KEY
<- connect(server = URL, api_key = API_KEY) client
Discussion
The Posit SDK client provide an idomatic interface to Posit Connect. The client object accepts credential information, which can be provided at runtime or defined inline. The preferred method for credential injection is at runtime through environment variables. This protects your information from accidentally being shared along with source code that uses the Posit SDK.