Skip to main content

A Python library to securely handle sensitive in-memory variables with authorized access controls.

Project description

PyShield

PyShield is a professional Python library designed to securely handle sensitive in-memory variables such as passwords, tokens, API keys, and payment data. It wraps these values in protected objects that prevent accidental exposure during printing, logging, or debugging, while providing controlled access through authorization mechanisms.

Features

  • Masking: Displays a mask (e.g., "*****") instead of the real value in print(), str(), or repr().
  • Authorized Access: Enforces checks via passkey, custom callbacks, access limits, expiration, environment verification, and caller inspection.
  • Secure Deletion: Wipes the value from memory to prevent further access.
  • Access Logging: Logs all access attempts for auditing.
  • Thread-Safety: Safe for use in multi-threaded environments.
  • Optional Encryption: Simple in-memory XOR encryption for added protection.
  • Python 3.7+ Support: Compatible with modern Python versions.

Installation

Install via PyPI:pip install pyshield

Usage

Basic Usage

from pyshield import ShieldedVar, AccessDeniedError

# Create a shielded variable with passkey authorization
secret = ShieldedVar("top_secret", passkey="my123")

print(secret)  # Outputs: *****
print(repr(secret))  # Outputs: <ShieldedVar: *****>

# Access with correct passkey
value = secret.get(passkey="my123")  # Returns: "top_secret"

# Access with wrong passkey
try:
    secret.get(passkey="wrong")
except AccessDeniedError:
    print("Access denied")

# Using callback authorization
def check_auth():
    # Dynamic logic, e.g., check user permissions
    return True

secret2 = ShieldedVar("another_secret", authorize=check_auth)
value2 = secret2.get()  # Returns value if check_auth() is True

# Return None on failure instead of raising
value_fail = secret.get(passkey="wrong", raise_on_fail=False)  # Returns: None

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

pyshield_secure-0.2.0.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

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

pyshield_secure-0.2.0-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file pyshield_secure-0.2.0.tar.gz.

File metadata

  • Download URL: pyshield_secure-0.2.0.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for pyshield_secure-0.2.0.tar.gz
Algorithm Hash digest
SHA256 a507ab89d773a6083fc89400345bc08fa2d1a4994df5e1bba8d0fb366f512af8
MD5 d9343498f8f220de7cc079d26e8636bf
BLAKE2b-256 9ab9820a21770740842ef9c95a6ca5845cef6ecdf3f40fddf4f64d34fad3e0e9

See more details on using hashes here.

File details

Details for the file pyshield_secure-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pyshield_secure-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ee8534c58cfedabe13c5949d171daf2359666583a055ebcadb514a61aa3610a4
MD5 afdbb8fb944e8be04e1788e4ab98f29b
BLAKE2b-256 bd1fbfb70355103d6611511e678abd1bda343f8470b1a2f5f4d064d699111a6a

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