Skip to main content

Python SDK Configuration

The Python SDK (Async or Sync) client can be configured using an instance of the Config class.

from infrahub_sdk import Config, InfrahubClient
config = Config(address="http://infrahub:8080", api_token="123-xyz-invalid-token")
client = InfrahubClient(config=config)

The following settings can be defined in the Config class

address​

Description: The URL to use when connecting to Infrahub.
Type: string
Default value: http://localhost:8000
Environment variable: INFRAHUB_ADDRESS

api_token​

Description: API token for authentication against Infrahub.
Type: string
Environment variable: INFRAHUB_API_TOKEN

echo_graphql_queries​

Description: If set the GraphQL query and variables will be echoed to the screen
Type: boolean
Default value: False
Environment variable: INFRAHUB_ECHO_GRAPHQL_QUERIES

username​

Description: Username for accessing Infrahub
Type: string
Environment variable: INFRAHUB_USERNAME

password​

Description: Password for accessing Infrahub
Type: string
Environment variable: INFRAHUB_PASSWORD

default_branch​

Description: Default branch to target if not specified for each request.
Type: string
Default value: main
Environment variable: INFRAHUB_DEFAULT_BRANCH

default_branch_from_git​

Description: Indicates if the default Infrahub branch to target should come from the active branch in the local Git repository.
Type: boolean
Default value: False
Environment variable: INFRAHUB_DEFAULT_BRANCH_FROM_GIT

identifier​

Description: Tracker identifier
Type: string
Environment variable: INFRAHUB_IDENTIFIER

insert_tracker​

Description: Insert a tracker on queries to the server
Type: boolean
Default value: False
Environment variable: INFRAHUB_INSERT_TRACKER

max_concurrent_execution​

Description: Max concurrent execution in batch mode
Type: integer
Default value: 5
Environment variable: INFRAHUB_MAX_CONCURRENT_EXECUTION

mode​

Description: Default mode for the client
Type: object
Environment variable: INFRAHUB_MODE

pagination_size​

Description: Page size for queries to the server
Type: integer
Default value: 50
Environment variable: INFRAHUB_PAGINATION_SIZE

priority​

Description: Default request priority emitted as the X-Priority header on every request; one of high|medium|low (case-insensitive). When unset, no header is sent.
Type: object
Environment variable: INFRAHUB_PRIORITY

retry_delay​

Description: Base delay in seconds before retrying a request that failed with a transient error. The delay doubles after every attempt, with jitter, up to the maximum retry delay.
Type: integer
Default value: 5
Environment variable: INFRAHUB_RETRY_DELAY

retry_max_delay​

Description: Maximum delay in seconds between two retries of a request that failed with a transient error.
Type: integer
Default value: 60
Environment variable: INFRAHUB_RETRY_MAX_DELAY

retry_on_failure​

Description: Retry requests that fail with a transient error: connection error, timeout, an HTTP status listed in the retry status codes, or a GraphQL error the server flags with one of those statuses. Other errors are never retried. The maximum retry duration controls how long to keep retrying.
Type: boolean
Default value: False
Environment variable: INFRAHUB_RETRY_ON_FAILURE

retry_status_codes​

Description: HTTP status codes treated as transient when retrying on failure is enabled. Also matched against the HTTP status reported in GraphQL error extensions. 500 is included because Infrahub reports some transient database errors without further classification; remove it to fail fast on them.
Type: array
Default value: [500, 502, 503, 504]
Environment variable: INFRAHUB_RETRY_STATUS_CODES

rate_limit_retry_enabled​

Description: Retry requests that receive HTTP 429 using backoff. Set False to disable.
Type: boolean
Default value: True
Environment variable: INFRAHUB_RATE_LIMIT_RETRY_ENABLED

rate_limit_max_retries​

Description: Maximum number of retries after the initial attempt when receiving HTTP 429.
Type: integer
Default value: 10
Environment variable: INFRAHUB_RATE_LIMIT_MAX_RETRIES

rate_limit_backoff_base​

Description: Base interval in seconds for exponential backoff between 429 retries.
Type: number
Default value: 0.5
Environment variable: INFRAHUB_RATE_LIMIT_BACKOFF_BASE

rate_limit_backoff_max​

Description: Maximum wait in seconds for any single 429 retry (also clamps Retry-After).
Type: number
Default value: 60.0
Environment variable: INFRAHUB_RATE_LIMIT_BACKOFF_MAX

max_retry_duration​

Description: Maximum number of seconds to keep retrying a request that fails with transient errors when retrying on failure is enabled. Set to 0 to retry indefinitely.
Type: integer
Default value: 300
Environment variable: INFRAHUB_MAX_RETRY_DURATION

schema_converge_timeout​

Description: Number of seconds to wait for schema to have converged
Type: integer
Default value: 60
Environment variable: INFRAHUB_SCHEMA_CONVERGE_TIMEOUT

timeout​

Description: Default request timeout in seconds, applied to the read, write and pool phases of a request.
Type: integer
Default value: 60
Environment variable: INFRAHUB_TIMEOUT

connect_timeout​

Description: Timeout in seconds for establishing the TCP/TLS connection to Infrahub. Kept short so an unreachable address fails fast; it never exceeds the request timeout.
Type: integer
Default value: 10
Environment variable: INFRAHUB_CONNECT_TIMEOUT

transport​

Description: Set an alternate transport using a predefined option
Type: object
Environment variable: INFRAHUB_TRANSPORT

proxy​

Description: Proxy address
Type: string
Environment variable: INFRAHUB_PROXY

proxy_mounts​

Description: Proxy mounts configuration
Type: object
Environment variable: INFRAHUB_PROXY_MOUNTS

marketplace_url​

Description: Base URL for the Infrahub Marketplace.
Type: string
Default value: https://marketplace.infrahub.app
Environment variable: INFRAHUB_MARKETPLACE_URL

update_group_context​

Description: Update GraphQL query groups
Type: boolean
Default value: False
Environment variable: INFRAHUB_UPDATE_GROUP_CONTEXT

tls_insecure​

Description:
Indicates if TLS certificates are verified. Enabling this option will disable: CA verification, expiry date verification, hostname verification). Can be useful to test with self-signed certificates.
Type: boolean
Default value: False
Environment variable: INFRAHUB_TLS_INSECURE

tls_ca_file​

Description: File path to CA cert or bundle in PEM format
Type: string
Environment variable: INFRAHUB_TLS_CA_FILE

recorder​

Property: recorder

Description: Select builtin recorder for later replay.
Type: RecorderType
Default value: RecorderType.NONE

custom_recorder​

Property: custom_recorder

Description: Provides a way to record responses from the Infrahub API
Type: Recorder (protocol)
Default value: NoRecorder.default

requester​

Property: requester

Type: AsyncRequester
Default value: None

sync_requester​

Property: sync_requester

Type: SyncRequester
Default value: None