Skip to main content

A library for safe imports and scoped imports management.

Project description

SafeLib - Import Everything Safe

Safelib is an importer that supports fallback mechanism.

Example Usage

Using Context Manager (sync/async)

import safelib
from safelib import Import

with Import('typing', 'typing_extensions') as importer:
    # use traditional import
    from safelib import Protocol
    
    # use importer to access the final
    final = importer.final

    # use get_entity function to import override
    override = importer.get_entity('override')

Using Classical Imports

from safelib import _main, typing, _fallback, typing_extensions

from safelib import Protocol

# typing.Protocol or typing_extensions.Protocol
print(Protocol)

Reset State

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('typing', 'my_types') as importer:
    SafeEntity = importer.SafeEntity
    importer.reset_state()

For inquiries, feature request and bug reports, please contact me at contact@tomris.dev

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

safelib-0.3.0.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

safelib-0.3.0-py3-none-any.whl (3.3 kB view details)

Uploaded Python 3

File details

Details for the file safelib-0.3.0.tar.gz.

File metadata

  • Download URL: safelib-0.3.0.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.7

File hashes

Hashes for safelib-0.3.0.tar.gz
Algorithm Hash digest
SHA256 3a5ee46890a43c431776cf19cb3ea6bd7dd69e81d205b81eb212703724dc37a8
MD5 a032f6282484937dda5b617d806014e5
BLAKE2b-256 8a070aa24f4e58fc8f8241e071e16c8d690dd43668196217b06134b40d9edc32

See more details on using hashes here.

File details

Details for the file safelib-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: safelib-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 3.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.7

File hashes

Hashes for safelib-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 181317d472bb3e9b851c62fb38b64f3a42c64fd36f61599fc4be9cb139fe3257
MD5 8d4d7c3ef3710b53d4193d6f2158748e
BLAKE2b-256 5b372199242db8eca07b6f3227571b65a342f701296c515f53fe9d2372b0413b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page