Configuration

Create a files_sdk.Client with the settings it needs. A client never reads the module-level settings, and its objects keep using it. See Clients for per-call options, clients with your own Requests session, and closing.

The module-level functions, such as files_sdk.user.find(), use the settings on the files_sdk module instead, as they are when each call starts.

Example setting

import files_sdk

client = files_sdk.Client(
  api_key="YOUR_API_KEY",
  base_url="https://SUBDOMAIN.files.com",
  workspace_id=5,
  open_timeout=30,
  read_timeout=80,
  max_network_retries=3,
  request_timeout=None,
)

Client Settings

SettingDefaultMeaning
api_key, session_id, sessionThe credential. With both, the API key is used.
workspace_id, language, headersSent with every API request.
base_urlhttps://app.files.comWhere the API is. See Base URL below.
open_timeout, read_timeout30, 80Seconds to wait for a connection to each resolved address, and for each read.
max_network_retries3Retries of a failed request; 0 sends it once.
initial_network_retry_delay, max_network_retry_delay0.1, 2Seconds API retries wait, doubling.
request_timeoutNoneSeconds each operation may take in all.
max_redirects30Redirects each request may follow.
source_ipThe local address to send from.
verify, cert, proxies, trust_envTrue, None, None, TrueAs for requests.Session.
http_sessionYour own requests.Session to send through.
transfer_limiter, upload_tuningA limiter of its own, adaptiveSee Uploads.
region_policy, region_handler, region_development_origins"automatic"See Regional Relocation.

Retries and Timeouts and Cancellation and Deadlines describe the timing settings.

Module Settings

Base URL

Set this to the full https:// URL of your Files.com subdomain (e.g. https://MY-SUBDOMAIN.files.com). This is not required in most cases, but one benefit of setting it is that it ensures that authentication failures will be logged to your site's API logs. Without setting this, we won't know which site to associate the authentication failure with, and it won't be logged to your site's API logs. This is always required if your site is configured to disable global acceleration. This can also be set to use a mock server in development or CI. A client takes the same value as its base_url setting.

Example setting

import files_sdk

files_sdk.base_url = "https://SUBDOMAIN.files.com"

Log Level

This SDK uses the standard Python logging framework, through the files_sdk logger. The SDK logs nothing until your application configures logging. At INFO it logs each request, response and retry without credentials or signed URLs; at DEBUG it logs complete requests and responses, including credentials, signed URLs and file content, so enable DEBUG only where those can be kept safe.

Example setting

import logging

logging.basicConfig()
logging.getLogger("files_sdk").setLevel(logging.INFO)

Console Log Level

Also prints the SDK's messages at or above this level to stderr, however logging is configured.

Allowed values are:

  • "none" (the default)
  • "error"
  • "warning"
  • "info"
  • "debug"

Example setting

import files_sdk

files_sdk.console_log_level = "info"

Open Timeout

Seconds to wait for a connection to each address the host name resolves to. The default value is 30.

Example setting

import files_sdk

files_sdk.open_timeout = 60

Read Timeout

Read timeout in seconds, for each read of a response. The default value is 80.

Example setting

import files_sdk

files_sdk.read_timeout = 90

Initial Network Retry Delay

Seconds before the first retry of an API request, doubling for each later retry. The default value is 0.1.

Example setting

import files_sdk

files_sdk.initial_network_retry_delay = 1

Maximum Retry Delay

Maximum network retry delay in seconds. The default value is 2.

Example setting

import files_sdk

files_sdk.max_network_retry_delay = 5

Maximum Network Retries

Maximum number of retries after the first attempt. The default value is 3; 0 sends each request once.

Example setting

import files_sdk

files_sdk.max_network_retries = 5

Source IP

Configure the local IP address from which to send requests.

Example setting

import files_sdk

files_sdk.source_ip = '10.1.2.3'