> ## Documentation Index
> Fetch the complete documentation index at: https://encrova-docs.platform.ai71services.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Python SDK

A Python SDK for platform encryption operations, providing secure encryption and decryption capabilities.

<Note>
  **Related Links**

  * [Github Repo](https://github.com/LocAI1/platform-encryption-python-sdk)
</Note>

***

## Pre-requisites

<Steps>
  <Step title="Request repository access to the Packages">
    Reach out to Platform team to request access to the Packages repository:

    * [Slack](https://locai-workspace.slack.com/archives/C07MX00L8EN)
  </Step>

  <Step title="Requirements">
    <li>Python 3.7+</li>
    <li>API & Secret Key</li>

    <Warning>
      Reach out to Platform team for any assistance.
      <ul>You can generate an API and Secret Key using the Encryption Service APIs. Refer to the API Reference for further details.</ul>
    </Warning>
  </Step>
</Steps>

***

## Installation

```bash
pip install git+https://github.com/LocAI1/platform-encryption-python-sdk.git
```

If you encounter an HTTP 404 error, please follow these steps:

```bash
brew install gh
gh auth login
pip install git+https://github.com/LocAI1/platform-encryption-python-sdk.git
```

***

## Usage

See the example below or check <code>example.py</code> for detailed usage:

```python


import asyncio

from encrova_sdk.EncrovaSDKClient import EncrovaSDKClient

async def main():
    """
    Demonstrates the usage of Encrova SDK for encryption and decryption
    operations.

    The example shows:
    1. Initializing the Encrova SDK client with symmetric or asymmetric encryption
    2. Encrypting a JSON payload containing identity provider configurations
    3. Decrypting the encrypted JWE (JSON Web Encryption) token
    """

    # Initialize Encrova SDK client with symmetric or asymmetric encryption mode
    # encryption_type can be either "symmetric" or "asymmetric"
    encrova_client = EncrovaSDKClient(
                host="http://localhost:8000",
                encryption_type="symmetric"
    )

    # Encrypt a JSON payload using the encrypt API
    # Parameters:
    # - payload: JSON object containing the data to be encrypted
    # - api_key: API key for authentication
    # - secret_key: Secret key used for encryption
    jwe = await encrova_client.service.encrypt(
        payload={"username" : "udayakumar.rajan", "password" : "random"},
        api_key="<API Key>",
        secret_key="<Secret Key>"
    )
    print(f"jwe : {jwe}")

    # Decrypt the JWE token using the decrypt API
    # Parameters:
    # - jwe: The encrypted JWE token to be decrypted
    # - api_key: API key for authentication
    plaintext = await encrova_client.service.decrypt(
        jwe=jwe,
        api_key="<API Key>"
    )
    print(f"plain text : {plaintext}")


""" Run the async main function """
if __name__ == "__main__":
    asyncio.run(main())

```
