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

client = connect.Client()
library(connectapi)

client <- connect()

Option 2

Create a Posit Connect client and define credential information inline.

Warning

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

CONNECT_SERVER = "https://connect.example.com"
CONNECT_API_KEY = "abcdefghijklmnopqrstuvwxyz123456"

client = connect.Client(CONNECT_SERVER, CONNECT_API_KEY)
library(connectapi)

CONNECT_SERVER = "https://connect.example.com"
CONNECT_API_KEY = "abcdefghijklmnopqrstuvwxyz123456"

client <- connect(server = CONNECT_SERVER, api_key = CONNECT_API_KEY)

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.