Python
Encrypting/Decrypting data with our backend SDKs may expose you to greater compliance burden because your server needs to handle plaintext data. Instead, we recommend using Relay or our Client-Side SDKs to encrypt data.
Getting started
Install the SDK
Our Python SDK is distributed via pypi, and can be installed using pip.
Initialize the SDK
The SDK needs to be initialized with an App's ID and API key. If you don't have one yet, you can get one by creating an App in the Evervault Dashboard.
Encrypt a string
Now that the SDK is initialized, we can encrypt a string.
Reference
init
Initializes the SDK with your API Key and App ID.
Parameters
Your Evervault App's ID.
Your Evervault App's API Key.
encrypt
Encrypts data using Evervault Encryption. To encrypt a string using the Python SDK, simply pass a str or a dict, to encrypt a file, pass a bytes or bytearray. The encrypted data can be stored in your database or file storage as normal. Evervault Strings can be used across all of our products. Evervault File Encryption is currently in Beta, and files can only be decrypted with Relay.
decrypt
Decrypts the data previously encrypted with the encrypt() function or through Relay. An API key with the decrypt permission must be used to perform this operation.
PCI Compliance
run
Lets you invoke an Evervault Function with a given payload.
Parameters
The name of the function to invoke.
The payload to pass to the function.
Whether to run the Function asynchronously or not. Callback URL must be configured in the Evervault Dashboard to receive a webhook on Function completion. Asynchronous Function invocations must be enabled for your team by contacting support@evervault.com.
Successful Function runs will return a dictionary containing a Function Run ID and the result from your Function in the following format:
In the case of an asynchronous Function invocation the result will be in the following format:
create_run_token
Creates a single use, time bound token (5 minutes) for invoking an Evervault Function with a given payload. Run Tokens can be used to invoke an Evervault Function client-side without providing a sensitive API Key.
Parameters
The name of the function to invoke.
Payload that the token can be used with. If not provided, a run token will be created, and the payload will not be validated when the function is executed.
create_client_side_decrypt_token
Client Side Decyrpt Tokens are versatile and short-lived tokens that frontend applications can utilise to decrypt data previously encrypted through Evervault. Client Side Decrypt Tokens are restricted to specific payloads. By default, a Client Side Decrypt Token will live for 5 minutes into the future. The maximum time to live of the token is 10 minutes into the future.
Parameters
The data to decrypt.
The time the token will expire. Defaults to 5 minutes in the future.
When you create a Run Token, the SDK will return a JSON object containing your token.
Run Tokens can then be used to authenticate Function runs from the client-side.
enable_outbound_relay
This should only be used when you need to configure third party SDKs with Relay. All other use cases should call Relay with a HTTP Client.
Configures your application to proxy HTTP requests using Relay based on the configuration created in the Evervault dashboard. See Relay to learn more.
Asynchronous HTTP requests are supported with aiohttp. Pass in a aiohttp.ClientSession to enable them for that session.
Parameters
Requests sent to any of the domains listed will be proxied through Relay. This will override the configuration created using the Evervault dashboard.
Output request domains and whether they were sent through Relay.
The aiohttp client session to enable relay on. Requires Python 3.11+.
attestable_encalve_session
Returns a Requests session with will attest your Enclave during the TLS handshake.
By default the client will attest the Enclave using the attestation document but will not make any assertions about the values of the PCRs. The attestation can be further scoped to the software running in your enclave by passing a dict mapping Enclave names to their corresponding PCRs.
Parameters
Optional constraints to assert that the PCRs present in the Enclave's attestation doc match the expected values. This can be either a single dict, or a list of dicts to allow roll-over between different sets of PCRs.You can also provide a callback function which returns a set of PCRs for an Enclave. This can make it easier to migrate your clients across Enclave deployments as the PCRs inevitably change.
Using the Evervault API as a PCR Provider
The Evervault API exposes an endpoint to retrieve the PCRs for all active deployments of an Enclave. This can be used to keep your Client in sync with your Enclave across deployments.