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

# 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.1.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.1.0-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyshield_secure-0.1.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.1.0.tar.gz
Algorithm Hash digest
SHA256 f4f9ff7673642850c8403ceab280863362981f677984619869ef69dc70b53c4b
MD5 e83f36989fa3436fe3cbd68c1644c534
BLAKE2b-256 2e3349dc722f54b31cb24a561a90b1c5ef41b56b8095f0afb2f5f691392ce15a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyshield_secure-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b04d70205c1a7813813a6b7b918862b84e1c251bd355b2cd48ffb56da3e71e6e
MD5 862302862baf094aebcfd84533ec633d
BLAKE2b-256 ae7e92ce5ffbe8c1ce2ecaca09bb6927638026bdf4782d6a77e6f48ae8058a1f

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