Skip to main content

Client for interacting with Pinapple

Project description

🍍 PinappleClient 🍍

A Python client for interacting with the Pinapple encryption API.

🚀 Features

  • Authentication 🔐 - Token-based API authentication with automatic refresh
  • Flexible Encryption ⚡ - Support for strict and loose encryption modes
  • Fallback Strategy 🔄 - Automatic fallback from strict to loose encryption
  • Smart Token Management ⏰ - Configurable token refresh with expiration handling
  • Robust Network Handling 🔁 - Automatic retries with configurable backoff for network issues

📦 Installation

pip install PinappleClient

🔧 Quick Start

from pinapple_client import PinappleClient

# Initialize client with automatic token refresh and network resilience
client = PinappleClient(
    user="your_username",
    password="your_password",
    api_url="https://api.pinapple.com",
    refresh_token_after_x_minutes=5,  # Refresh token 5 minutes before expiration
    timeout=30,                       # Request timeout in seconds
    max_retries=3,                    # Number of retry attempts
    backoff_base=2                    # Exponential backoff base (2s, 4s, 8s)
)

# Encrypt a single PIN
encrypted_pin = client.encrypt_pin_strict("123456")
print(f"Encrypted: {encrypted_pin}")

# Decrypt data
decrypted_pin = client.decrypt_pin(encrypted_data)
print(f"Decrypted: {decrypted_pin}")

📊 DataFrame Operations

encrypt_dataframe(df, column, strict=True, strict_then_loose=False) -> DataFrame

Encrypts an entire column in a pandas DataFrame.

import pandas as pd

df = pd.DataFrame({
    'id': [1, 2, 3],
    'pin': ['123456', '789012', '345678']
})

# Encrypt the 'pin' column
encrypted_df = client.encrypt_dataframe(df, 'pin', strict=True)

# Use fallback strategy
encrypted_df = client.encrypt_dataframe(df, 'pin', strict_then_loose=True)

Parameters:

  • df: Input DataFrame
  • column: Column name to encrypt
  • strict: Use strict encryption (default: True)
  • strict_then_loose: Enable fallback strategy (default: False)

🔒 Authentication & Token Management

The client automatically handles token management with intelligent refresh:

Automatic Token Refresh

  • Requests a bearer token on first API call
  • Caches the token for subsequent requests
  • Automatically refreshes tokens before expiration based on configurable buffer time
  • Handles long-running operations without token expiry issues

Token Configuration

# Refresh token 10 minutes before it expires
client = PinappleClient(..., refresh_token_after_x_minutes=10)

# Check token status
expiration = client.get_token_expiration()
should_refresh = client.should_refresh_token()

Token Utilities

  • get_token_expiration() - Returns token expiration as datetime
  • should_refresh_token() - Checks if token needs refresh based on buffer
  • Automatic refresh during long DataFrame operations

Perfect for long-running encryption jobs - no manual token management required!

🔁 Network Resilience

The client includes robust network error handling for unreliable connections:

Automatic Retry Logic

  • Connection errors (DNS resolution, network unreachable)
  • Timeout errors (slow network responses)
  • Request exceptions (various network issues)

Configurable Retry Parameters

client = PinappleClient(
    ...,
    timeout=45,        # Longer timeout for slow networks
    max_retries=5,     # More retry attempts
    backoff_base=3     # Aggressive backoff (3s, 9s, 27s, 81s, 243s)
)

Retry Behavior

  • Exponential backoff: Wait time = backoff_base ^ (attempt + 1)
  • Default settings: 3 retries with 2s, 4s, 8s delays
  • Progress feedback: Logs each retry attempt with wait time
  • Final failure: Clear error message after all retries exhausted

Ideal for corporate networks and VPN connections with intermittent connectivity issues!

📄 License

This project is licensed under the GPL-3.0 License.

🔗 Links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pinappleclient-1.4.1.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pinappleclient-1.4.1-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file pinappleclient-1.4.1.tar.gz.

File metadata

  • Download URL: pinappleclient-1.4.1.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for pinappleclient-1.4.1.tar.gz
Algorithm Hash digest
SHA256 35e1a643a26c755be5f8ddfbc1004d09c3cf74a59161acf00258aca160d3f45d
MD5 4b696b0e74770ec89012ad5ba6f91f8e
BLAKE2b-256 9410e163188424a8b40f09852ce34abc21f899d9e18adfc6b34da490a93c0020

See more details on using hashes here.

File details

Details for the file pinappleclient-1.4.1-py3-none-any.whl.

File metadata

  • Download URL: pinappleclient-1.4.1-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for pinappleclient-1.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bf7ce12614844722f93cd4b5b6a4af17b2380cad36a3af9082f6a8a90ab4268f
MD5 24c8d54cd6a24a8867da82293b9f7dd9
BLAKE2b-256 62ae75e8ee1a7d7fe61cd5972f017c94f544aadc5e622c622c7d8c8804543e86

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page