README
Incident Response SDK for Python
Developer-friendly & type-safe Python SDK specifically catered to leverage Incident Response API.
Summary
Squadcast: ## Overview The Squadcast API provides developers the capability to extend and utilize Squadcast in conjunction with other services. Our API has resource-oriented URLs, accepts JSON-encoded request bodies, returns JSON-encoded responses, and uses standard HTTP response codes, authentication, and verbs.
Note: Customers using the V2 version of the Squadcast API would need to migrate to Squadcast API V3, as the former would be deprecated shortly.
Service Regions
Squadcast allows customers to choose the geographic region of the Squadcast data centers that host their account. When signing up, you can choose the service region. Currently, the available options are the United States (US) and Europe (EU).
US
Authentication: https://auth.squadcast.com · Other APIs: https://api.squadcast.com
EU
Authentication: https://auth.eu.squadcast.com · Other APIs: https://api.eu.squadcast.com
Authentication
In order to access the API programmatically, HTTP bearer authentication needs to be used. HTTP bearer authentication must be constructed using an access_token, passed as the Authorization header for each request, for example Authorization: Bearer eyJleHAiOjE2MzU1OTE1OTIsImp0aSI6Im.
Steps to procure the access_token:
Generate a
refresh_token(API Token) from the Squadcast web app. More details on how to get therefresh_tokencan be found in the Squadcast support documentation.Call the authentication API with the
refresh_tokento obtain anaccess_token.Use the
access_tokenas a Bearer token in theAuthorizationheader for all subsequent API requests.
Example — Generating an Access Token
The API response will look similar to:
Access Control
There are three different types of user roles in Squadcast: account_owner, stakeholder, and user. Refresh tokens upon creation are mapped with one of the mentioned user roles, and access to different resources is dependent on the permissions granted to these roles. For more information, please refer to the Squadcast support documentation.
Authorization
The access token authorizes users the ability to access different APIs, based on the user roles described above. Pass the access token as a Bearer token in the Authorization header of every request.
Table of Contents
SDK Installation
[!NOTE] Python version upgrade policy
Once a Python version reaches its official end of life date, a 3-month grace period is provided for users to upgrade. Following this grace period, the minimum python version supported in the SDK will be updated.
The SDK can be installed with uv, pip, or poetry package managers.
uv
uv is a fast Python package installer and resolver, designed as a drop-in replacement for pip and pip-tools. It's recommended for its speed and modern Python tooling capabilities.
PIP
PIP is the default package installer for Python, enabling easy installation and management of packages from PyPI via the command line.
Poetry
Poetry is a modern tool that simplifies dependency management and package publishing by using a single pyproject.toml file to handle project metadata and dependencies.
Shell and script usage with uv
You can use this SDK in a Python shell with uv and the uvx command that comes with it like so:
It's also possible to write a standalone Python script without needing to set up a whole project like so:
Once that is saved to a file, you can run it with uv run script.py where script.py can be replaced with the actual file name.
IDE Support
PyCharm
Generally, the SDK will work well with most IDEs out of the box. However, when using PyCharm, you can enjoy much better integration with Pydantic by installing an additional plugin.
SDK Example Usage
Example
The same SDK client can also be used to make asynchronous requests by importing asyncio.
Authentication
Per-Client Security Schemes
This SDK supports the following security scheme globally:
refresh_token_auth
http
Custom HTTP
To authenticate with the API the refresh_token_auth parameter must be set when initializing the SDK client instance. For example:
Available Resources and Operations
Pagination
Some of the endpoints in this SDK support pagination. To use pagination, you make your SDK calls as usual, but the returned response object will have a Next method that can be called to pull down the next group of results. If the return value of Next is None, then there are no more pages to be fetched.
Here's an example of one such pagination call:
File uploads
Certain SDK methods accept file objects as part of a request body or multi-part request. It is possible and typically recommended to upload files as a stream rather than reading the entire contents into memory. This avoids excessive memory consumption and potentially crashing with out-of-memory errors when working with very large files. The following example demonstrates how to attach a file stream to a request.
[!TIP]
For endpoints that handle file uploads bytes arrays can also be used. However, using streams is recommended for large files.
Retries
Some of the endpoints in this SDK support retries. If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API. However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.
To change the default retry strategy for a single API call, simply provide a RetryConfig object to the call:
If you'd like to override the default retry strategy for all operations that support retries, you can use the retry_config optional parameter when initializing the SDK:
Error Handling
SquadcastSDKError is the base class for all HTTP error responses. It has the following properties:
err.message
str
Error message
err.status_code
int
HTTP response status code eg 404
err.headers
httpx.Headers
HTTP response headers
err.body
str
HTTP body. Can be empty string if no body is returned.
err.raw_response
httpx.Response
Raw HTTP response
Example
Error Classes
Primary errors:
SquadcastSDKError: The base class for HTTP error responses.PaymentRequiredError: Client error. Status code402. *ForbiddenError: Access is forbidden. Status code403. *NotFoundError: The server cannot find the requested resource. Status code404. *ConflictError: The request conflicts with the current state of the server. Status code409. *UnprocessableEntityError: Client error. Status code422. *InternalServerError: Server error. Status code500. *BadGatewayError: Server error. Status code502. *ServiceUnavailableError: Service unavailable. Status code503. *GatewayTimeoutError: Server error. Status code504. *UnauthorizedError: Access is unauthorized. Status code401. *BadRequestError: The server could not understand the request due to invalid syntax. Status code400. *
* Check the method documentation to see if the error is applicable.
Server Selection
Select Server by Index
You can override the default server globally by passing a server index to the server_idx: int optional parameter when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the indexes associated with the available servers:
0
https://api.squadcast.com
production US env
1
https://api.eu.squadcast.com
production EU env
Example
Override Server URL Per-Client
The default server can also be overridden globally by passing a URL to the server_url: str optional parameter when initializing the SDK client instance. For example:
Custom HTTP Client
The Python SDK makes API calls using the httpx HTTP library. In order to provide a convenient way to configure timeouts, cookies, proxies, custom headers, and other low-level configuration, you can initialize the SDK client with your own HTTP client instance. Depending on whether you are using the sync or async version of the SDK, you can pass an instance of HttpClient or AsyncHttpClient respectively, which are Protocol's ensuring that the client has the necessary methods to make API calls. This allows you to wrap the client with your own custom logic, such as adding custom headers, logging, or error handling, or you can just pass an instance of httpx.Client or httpx.AsyncClient directly.
For example, you could specify a header for every request that this sdk makes as follows:
or you could wrap the client with your own custom logic:
Resource Management
The SquadcastSDK class implements the context manager protocol and registers a finalizer function to close the underlying sync and async HTTPX clients it uses under the hood. This will close HTTP connections, release memory and free up other resources held by the SDK. In short-lived Python programs and notebooks that make a few SDK method calls, resource management may not be a concern. However, in longer-lived programs, it is beneficial to create a single SDK instance via a context manager and reuse it across the application.
Debugging
You can setup your SDK to emit debug logs for SDK requests and responses.
You can pass your own logger class directly into your SDK.
Development
Maturity
This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage to a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionally looking for the latest version.
Contributions
While we value open-source contributions to this SDK, this library is generated programmatically. Any manual changes added to internal files will be overwritten on the next generation. We look forward to hearing your feedback. Feel free to open a PR or an issue with a proof of concept and we'll do our best to include it in a future release.
SDK Created by Speakeasy
Last updated