SafeLib - Import Everything Safe
Safelib is an importer that supports fallback mechanism.
0.6.0 Changelog
- Fixed several issues
- Added safelib.valid instead importer.valid
- Added search_builtins feature
- Extended exception handling
Example Usage
Using Context Manager (sync/async)
import safelib
from safelib import Import
with Import('sqlalchemy', 'peewee', raises=False, search_builtins=True) as orm:
from safelib import declarative_base # use traditional import
Base = orm.declarative_base # use orm to access the declarative_base
# declarative_base can be found entity or safelib.NotFound
# because we set raises=False, it will not raise an exception if the entity is not found
# when we search for `int` with orm.int, it will search first in the builtins module
# and return the int type if found, or safelib.NotFound if not found.
# to validate whether an entity is valid, use:
if safelib.valid(orm.entity):
do_something_with(orm.entity)
Using Classical Imports
from safelib import _main, typing, _fallback, typing_extensions
from safelib import Protocol, _no_raise
#> Protocol is safelib.NotFound, typing.Protocol or typing_extensions.Protocol
from safelib import _no_raise # catch errors by defaulting missing entities
No-Raise Statement
Import _no_raise sentinel to catch exceptions in current state.
from safelib import _main, typing
from safelib import _no_raise, Protocool
# Protocool is safelib.NotFound, otherwise raises exception
import safelib
with safelib.Import(raises=False) as foo:
# use context manager of Import with raises=False
# or call safelib.catch() before context manager
pass
Reset Statement
Import _reset sentinel to reset current state of safelib.
from safelib import _main, httpx
# after get method returned, state will be restored to initial state
from safelib import get, _reset
from safelib import Import
async with Import('sqlalchemy', 'peewee') as importer:
SafeEntity = importer.SafeEntity
importer.reset_state()
For inquiries, feature request and bug reports, please contact me at contact@tomris.dev
Metadata
Release files for safelib 0.6.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 |
|---|---|---|---|---|
| safelib-0.6.1.tar.gz | 4.7 kB | Without provenance | Details for safelib-0.6.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| safelib-0.6.1-py3-none-any.whl | Python 3 | none | any | Details for safelib-0.6.1-py3-none-any.whl |
Total release size: 9.9 kB
Release files / safelib-0.6.1.tar.gz
| Download URL | safelib-0.6.1.tar.gz |
|---|---|
| Size | 4.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
08bd3b8781a85cf91c5d7f486840398cec2836f7773f1f52d1fb80401bd5cc7a
|
|
BLAKE2b-256 checksum How to use checksums |
59d7433f939d4691b2a2501daa65339dede927e1caa1fc84c2d64ffdc11dbd76
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.7
|
Release files / safelib-0.6.1-py3-none-any.whl
| Download URL | safelib-0.6.1-py3-none-any.whl |
|---|---|
| Size | 5.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1c6c3f1e3af5fa919ff90c73ae10746753a3851db534db4fffabe9ee2031feaa
|
|
BLAKE2b-256 checksum How to use checksums |
36cef5aab2332d927f8b300517ae186d31199f569768fb153f909e73042918df
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.7
|
Security for safelib 0.6.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.