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(), orrepr(). - 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a507ab89d773a6083fc89400345bc08fa2d1a4994df5e1bba8d0fb366f512af8
|
|
| MD5 |
d9343498f8f220de7cc079d26e8636bf
|
|
| BLAKE2b-256 |
9ab9820a21770740842ef9c95a6ca5845cef6ecdf3f40fddf4f64d34fad3e0e9
|
File details
Details for the file pyshield_secure-0.2.0-py3-none-any.whl.
File metadata
- Download URL: pyshield_secure-0.2.0-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ee8534c58cfedabe13c5949d171daf2359666583a055ebcadb514a61aa3610a4
|
|
| MD5 |
afdbb8fb944e8be04e1788e4ab98f29b
|
|
| BLAKE2b-256 |
bd1fbfb70355103d6611511e678abd1bda343f8470b1a2f5f4d064d699111a6a
|