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
Metadata
Release files for pyshield-secure 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pyshield_secure-0.2.0.tar.gz | 4.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pyshield_secure-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.4 kB
Release files / pyshield_secure-0.2.0.tar.gz
| Download URL | pyshield_secure-0.2.0.tar.gz |
|---|---|
| Size | 4.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a507ab89d773a6083fc89400345bc08fa2d1a4994df5e1bba8d0fb366f512af8
|
|
BLAKE2b-256 checksum How to use checksums |
9ab9820a21770740842ef9c95a6ca5845cef6ecdf3f40fddf4f64d34fad3e0e9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.5
|
Release files / pyshield_secure-0.2.0-py3-none-any.whl
| Download URL | pyshield_secure-0.2.0-py3-none-any.whl |
|---|---|
| Size | 4.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ee8534c58cfedabe13c5949d171daf2359666583a055ebcadb514a61aa3610a4
|
|
BLAKE2b-256 checksum How to use checksums |
bd1fbfb70355103d6611511e678abd1bda343f8470b1a2f5f4d064d699111a6a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.5
|