SDK Initialization

SDK Initialization

The PageSense Python SDK is initialised using the PageSenseClientBuilder class. During initialization, the SDK downloads the latest project configuration from the PageSense server and creates a PageSenseClient instance that can be used to evaluate experiments and track goals throughout the application lifecycle. During initialization, the SDK downloads the latest project configuration from the PageSense server and stores it in memory. The in-memory configuration is then periodically synchronised based on the configured polling interval, allowing experiment changes to take effect without restarting the application. It is recommended to initialise the SDK once during application startup and reuse the same PageSenseClient instance for all subsequent experiment evaluations and goal tracking operations.

Builder Parameters  

Parameter

Type

Required

Description

sdk_account_id

str

Yes

Unique PageSense SDK account identifier.

sdk_key

str

Yes

SDK key associated with the PageSense project.

project_name

str

Yes

Name of the PageSense project.

sdk_options

PageSenseSDKOptions

No

Optional SDK configuration settings.

Return Value  

Type

Description

PageSenseClient

Initialized SDK client used to evaluate experiments and track goals.

Usage Example  

from pagesense import (
    PageSenseClient,
    PageSenseClientBuilder,
)

# Create the SDK client

pagesense_client: PageSenseClient = (
    PageSenseClientBuilder.create_new_pagesense_client(
        sdk_account_id,
        sdk_key,
        project_name
    )
)

Usage Example with SDK Options  

from pagesense import (
    PageSenseClient,
    PageSenseClientBuilder,
    PageSenseSDKOptions,
)

 

# Create the SDK Options object

sdk_options = (
    PageSenseSDKOptions()
        .add_log_level("DEBUG")
        .add_polling_interval(300)
)

# Create the SDK client

  1. pagesense_client: PageSenseClient = (
  2.     PageSenseClientBuilder.create_new_pagesense_client(
  3.         sdk_account_id,
  4.         sdk_key,
  5.         project_name,
  6.         sdk_options
  7.     )
  8. )

SDK Configuration Options  

The PageSenseSDKOptions class allows you to customize the SDK behaviour during initialization. All configuration options are optional. If no options are provided, the SDK uses the default configuration.

Method

Description

Default Value

add_log_level()

Configures the SDK log level.

INFO

add_polling_interval()

Configures the polling interval used to synchronise the project configuration.

10 seconds

add_custom_logger()

Registers a custom logger implementation.

Built-in logger

add_custom_storage()

Registers a custom user storage implementation.

In-memory user storage