Python private
This package is adding private/protected/public fields to Python.
Without PyPrivate:
class Foo():
__x = 7 # Private "x"
def baz(self):
self.__x += 7
def bar(f, n):
try:
getattr(f, n)
except:
print('"' + n + '" not found')
else:
print('"' + n + '" found')
myfoo = Foo()
myfoo.baz()
bar(myfoo, "__x") # "__x" not found
bar(myfoo, "_Foo__x") # "_Foo__x" found
With PyPrivate:
from privatefields import privatefields
@privatefields
class Foo():
private_x = 7 # Private "x"
def baz(self):
self.private_x += 7
def bar(f, n):
try:
getattr(f, n)
except:
print('"' + n + '" not found')
else:
print('"' + n + '" found')
myfoo = Foo()
myfoo.baz()
bar(myfoo, "private_x") # "private_x" not found
print(dir(myfoo)) # no "x"
How to use
PyPrivate is easy to use. To use private/protected fields import "privatefields":
from privatefields import privatefields
Next, use it with your classes:
@privatefields
class Foo():
pass
And add prefixes private_/protected_ to your variables/methods names:
self.z # Public
self.protected_y # Protected
self.private_x # Private
Friends
You can declare "friend" classes/functions. For this add this line to your class:
class Baz(): # This class can use "x"
pass
class Bar(): # This class can't use "x"
pass
@privatefields
class Foo():
friends = [Baz]
private_x = "Secret data" # Private "x"
What's new
0.2
- Added support for removing attributes (delattr).
- Replaced error message from "(name) object has no attribute (attribute)" to "attribute (attribute) is private/protected"
- Bugs fixed
0.3
- Added suppression of replacing
__attributewith_Class__attribute - Added flag pythonStyle. This flag replaces
private_with__andprotected_with_ - Bugs fixed
0.4
- A global improvement will be added. There will no longer be a need to use the
@privatefieldsdecorator. All classes will automatically have a private/protected fields system.
Planned before 0.9
- Added updated system (beta). Use flag updatedSystem to enable new system.
Metadata
Release files for PyPrivate 0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| PyPrivate-0.3.tar.gz | 4.6 kB | Without provenance | Details for PyPrivate-0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| PyPrivate-0.3-py3-none-any.whl | Python 3 | none | any | Details for PyPrivate-0.3-py3-none-any.whl |
Total release size: 9.3 kB
Release files / PyPrivate-0.3.tar.gz
| Download URL | PyPrivate-0.3.tar.gz |
|---|---|
| Size | 4.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
51b794cc91e3e361b5dfba605684178817b07e468dea9be718a59ba6d585a36a
|
|
BLAKE2b-256 checksum How to use checksums |
6b33f531d22c1260e6ef08b5030bea98a772fb988b9f92868642afee43b22261
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.8.1
|
Release files / PyPrivate-0.3-py3-none-any.whl
| Download URL | PyPrivate-0.3-py3-none-any.whl |
|---|---|
| Size | 4.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
812a6e9e669374478a093b5168a9af3258178043196119daffcb91f8df7aa2c1
|
|
BLAKE2b-256 checksum How to use checksums |
e7b2ca014f5671099fd95343b524a2344fd6ddf6156e4e4efe02bec2573023a6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.8.1
|
Security for PyPrivate 0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.