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.4.0.tar.gz (3.5 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.4.0-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for safelib-0.4.0.tar.gz
Algorithm Hash digest
SHA256 a8f9f391d2a95d268078b5bc28a6b098f7dfe42f4d5ea85c26baf5418b604a98
MD5 4302ec7bcb6f07bab5a77a8892dbbb58
BLAKE2b-256 335c4f792aea896e3830643b88cc0ae887bd819d7ec6f2455fc2be532a0e693b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: safelib-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 3.6 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.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 169dde26b8252ab262fc7b08874995124ad96beabaf95d4a5e834c5dc64ba239
MD5 5fa93873d13bfa7bfb23e5fc09d446bb
BLAKE2b-256 b2a5a33322de96d6a26ef336e9c52cbdec5771af522723bddf380afa8ccff725

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