==============
Tired of always checking hasattr, len, or if a key is in a dictionary? safe_access allows
you to safely drill down multiple levels into any python object without having to worry about
AttributeErrors, KeyErrors, or IndexErrors. Oh, and it supports wildcards.
*Available on pypi*: https://pypi.python.org/pypi/safe_access
python
from safe_access import safe_access
class A(object):
pass
a = A()
a.b = {"abc": ['x', 'y', 'z'], "def": [1, 2, 3]}
# Access valid path
print safe_access(a, 'a.b["abc"][1]', default_value=7)
# returns 'y'
# Access valid path with variable substitution
myvar = 1
print safe_access(a, 'a.b["abc"][myvar]', default_value=7, myvar=myvar)
# returns 'y'
# Access that causes index out of range, but returns default value of 7
print safe_access(a, 'a.b["abc"][404]', default_value=7)
# returns 7
# Access non-existant attribute
print safe_access(a, 'a.bad_attribute')
# returns None
# Access wildcard
print safe_access(a, 'a.b[*][0]')
# returns ['x', 1]
Limitations:
\1. Does not support function calls at this time
\2. Does not support escaped quotations
\3. Does not support variable references withing tuple literals
Metadata
Release files for safe_access 1.1
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 |
|---|---|---|---|---|
| safe_access-1.1.tar.gz | 9.4 kB | Without provenance | Details for safe_access-1.1.tar.gz |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| safe_access-1.1.macosx-10.10-intel.tar.gz | Details for safe_access-1.1.macosx-10.10-intel.tar.gz | |||
| safe_access-1.1-py2.7.egg | Legacy Egg format | - | - | Details for safe_access-1.1-py2.7.egg |
Total release size: 19.2 kB
Release files / safe_access-1.1.tar.gz
| Download URL | safe_access-1.1.tar.gz |
|---|---|
| Size | 9.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4b2cac1dbec8844998e5208416140bb4b8b910628033b9f025eb28bdca2e3465
|
|
BLAKE2b-256 checksum How to use checksums |
5a96c5013d08c413205e26bcd37e68da43938d7b798ddbf7f6ada7b0e47467c3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / safe_access-1.1.macosx-10.10-intel.tar.gz
| Download URL | safe_access-1.1.macosx-10.10-intel.tar.gz |
|---|---|
| Size | 4.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
00be74f31ab945f0677ef18b3afed982d4926468a9412e0d7364343af8798261
|
|
BLAKE2b-256 checksum How to use checksums |
993b2ec3bd0abc30b50a4a2d4095f7b2d9957b1986ce6aa892f96c7a2557c885
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / safe_access-1.1-py2.7.egg
| Download URL | safe_access-1.1-py2.7.egg |
|---|---|
| Size | 5.5 kB |
| Tags | Egg |
|
SHA-256 checksum How to use checksums |
319576ba408ccda8cd80bd88a598ea13a2fc28e9dfe2a4db50f6c0ea79639e06
|
|
BLAKE2b-256 checksum How to use checksums |
ae4d350c01be2034fb59414ee61a44b29a3e0aed62aaa729533f1628888aa94b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for safe_access 1.1
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.