Initializing a Client
Problem
You want to get started using the Posit SDK by initializing a connection to your server.
Solution
Option 1 (Preferred)
Create a Posit Connect client and provide credential information using environment variables.
Variable | Description |
---|---|
CONNECT_API_KEY |
Your unique Posit Connect API key. |
CONNECT_SERVER |
Your Posit Connect server URL. |
export CONNECT_API_KEY = "abcdefghijklmnopqrstuvwxyz123456"
export CONNECT_SERVER = "https://connect.example.com"
export CONNECT_API_KEY = "abcdefghijklmnopqrstuvwxyz123456"
export CONNECT_SERVER = "https://connect.example.com"
set -x CONNECT_API_KEY "abcdefghijklmnopqrstuvwxyz123456" set -x CONNECT_SERVER "https://connect.example.com"
$Env:CONNECT_API_KEY = "abcdefghijklmnopqrstuvwxyz123456" $Env:CONNECT_SERVER = "https://connect.example.com"
set CONNECT_API_KEY=abcdefghijklmnopqrstuvwxyz123456 set CONNECT_SERVER=https://connect.example.com
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"
CONNECT_SERVER = "abcdefghijklmnopqrstuvwxyz123456"
CONNECT_API_KEY
= connect.Client(CONNECT_SERVER, CONNECT_API_KEY) client
library(connectapi)
= "https://connect.example.com"
CONNECT_SERVER = "abcdefghijklmnopqrstuvwxyz123456"
CONNECT_API_KEY
<- connect(server = CONNECT_SERVER, api_key = CONNECT_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.