Python SDK
SDK to integrate Phase in server-side applications running Python.
The Python SDK allows you to encrypt data server-side, as well as decrypt data.
In order to use the Python SDK you will need to create a new App on the Phase
Console. Add the APP_ID
and APP_SECRET
to your application, preferably
using environment variables. Quick start »
Install the SDK
The Python SDK is distributed via PyPI. You can install it using the following command.
Install
pip install phase-dev
Import the SDK
Once installed, you can import the Python SDK into your project.
from phase import Phase;
Initialize the SDK
Initialize the SDK with your APP_ID
and APP_SECRET
.
phase = Phase(APP_ID, APP_SECRET)
If you are self-hosting Phase, you must also provide the protocol and host for your Phase instance:
PHASE_INSTANCE_HOST = 'https://localhost'
phase = Phase(APP_ID, APP_SECRET, PHASE_INSTANCE_HOST)
Usage
Encrypt
The encrypt
API allows you to encrypt data. It returns an encrypted string in the Phase Ciphertext format.
ciphertext = phase.encrypt('hello world')
Decrypt
The decrypt
API allows you to decrypt a Phase Ciphertext string. It returns a plaintext string.
plaintext = phase.decrypt(ciphertext)