semvec/pypi-packages huggingface dataset:
dhanhq-utils 0.1.0
A lightweight utility library for encrypting and decrypting DhanHQ Web-API payloads with minimal setup.
License: Apache License 2.0
Requires Python: >=3.9

# dhanhq_utils

A lightweight utility library for **encrypting and decrypting DhanHQ Web-API payloads** with minimal setup.

### Installation

```bash
pip install dhanhq_utils
```

or (if using [uv](https://docs.astral.sh/uv/)):

```bash
uv add dhanhq_utils
```

---

### Usage

```python
import json
from dhanhq_utils import decrypt_payload, encrypt_payload

def encrypt(payload: dict) -> str:
    """Encrypt a Python dictionary into DhanHQ-compatible ciphertext."""
    return encrypt_payload(json.dumps(payload, separators=(',', ':')))

def decrypt(cipher_text: str) -> dict:
    """Decrypt DhanHQ ciphertext back into a Python dictionary."""
    return json.loads(decrypt_payload(cipher_text))

CIPHER_TEXT = "dhIs/M55xbI+qBzoZNUzHVOqGNb9XB0XTb4KB6hP04nr3/XD2Z8hM9x8EbjKq9f+JhWf7k+..."

PLAIN_TEXT = '{"kyc_status":"8","login_id":"9999999999","kyc_status_msg":"Invested User", ...}'

print(f"{decrypt(CIPHER_TEXT) = }")
print(f"{encrypt(json.loads(PLAIN_TEXT)) = }")
print(f"{encrypt_payload(PLAIN_TEXT) == CIPHER_TEXT = }")
```

---

### Notes

* Designed specifically for **DhanHQ Web-API encryption/decryption workflows**.
* Simplifies working with secure payloads in both **Python scripts** and **automated trading systems**.
* Supports seamless integration with JSON-based requests and responses.