safelib


Namesafelib JSON
Version 0.6.1 PyPI version JSON
download
home_pagehttps://github.com/fswair/safelib
SummaryAn advanced library for safe importing and scoped imports management.
upload_time2025-08-02 16:27:25
maintainerfswair
docs_urlNone
authorMert Sirakaya
requires_python>=3.10
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ##  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)
```python
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

```python
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.

```python
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.

```python
from safelib import _main, httpx
# after get method returned, state will be restored to initial state
from safelib import get, _reset 
```

```python
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

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/fswair/safelib",
    "name": "safelib",
    "maintainer": "fswair",
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": "contact@tomris.dev",
    "keywords": null,
    "author": "Mert Sirakaya",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/59/d7/433f939d4691b2a2501daa65339dede927e1caa1fc84c2d64ffdc11dbd76/safelib-0.6.1.tar.gz",
    "platform": null,
    "description": "##  SafeLib - Import Everything Safe\n\nSafelib is an importer that supports fallback mechanism.\n\n### 0.6.0 Changelog\n\n* Fixed several issues\n* Added safelib.valid instead importer.valid\n* Added search_builtins feature\n* Extended exception handling\n\n## Example Usage\n\n### Using Context Manager (sync/async)\n```python\nimport safelib\n\nfrom safelib import Import\nwith Import('sqlalchemy', 'peewee', raises=False, search_builtins=True) as orm:\n    from safelib import declarative_base # use traditional import\n    Base = orm.declarative_base # use orm to access the declarative_base\n\n    # declarative_base can be found entity or safelib.NotFound\n    # because we set raises=False, it will not raise an exception if the entity is not found\n\n    # when we search for `int` with orm.int, it will search first in the builtins module\n    # and return the int type if found, or safelib.NotFound if not found.\n\n    # to validate whether an entity is valid, use:\n    if safelib.valid(orm.entity):\n        do_something_with(orm.entity)\n```\n\n### Using Classical Imports\n\n```python\nfrom safelib import _main, typing, _fallback, typing_extensions\n\nfrom safelib import Protocol, _no_raise\n\n#> Protocol is safelib.NotFound, typing.Protocol or typing_extensions.Protocol\n\nfrom safelib import _no_raise # catch errors by defaulting missing entities\n```\n\n### No-Raise Statement\n\nImport `_no_raise` sentinel to catch exceptions in current state.\n\n```python\nfrom safelib import _main, typing\nfrom safelib import _no_raise, Protocool\n# Protocool is safelib.NotFound, otherwise raises exception\n\nimport safelib\n\nwith safelib.Import(raises=False) as foo:\n    # use context manager of Import with raises=False\n    # or call safelib.catch() before context manager\n    pass\n```\n\n### Reset Statement\n\nImport `_reset` sentinel to reset current state of safelib.\n\n```python\nfrom safelib import _main, httpx\n# after get method returned, state will be restored to initial state\nfrom safelib import get, _reset \n```\n\n```python\nfrom safelib import Import\n\nasync with Import('sqlalchemy', 'peewee') as importer:\n    SafeEntity = importer.SafeEntity\n    importer.reset_state()\n```\n\nFor inquiries, feature request and bug reports, please contact me at contact@tomris.dev\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "An advanced library for safe importing and scoped imports management.",
    "version": "0.6.1",
    "project_urls": {
        "Homepage": "https://github.com/fswair/safelib"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "36cef5aab2332d927f8b300517ae186d31199f569768fb153f909e73042918df",
                "md5": "87deebfd3996b1c5d790761ba2ae56d5",
                "sha256": "1c6c3f1e3af5fa919ff90c73ae10746753a3851db534db4fffabe9ee2031feaa"
            },
            "downloads": -1,
            "filename": "safelib-0.6.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "87deebfd3996b1c5d790761ba2ae56d5",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 5252,
            "upload_time": "2025-08-02T16:27:24",
            "upload_time_iso_8601": "2025-08-02T16:27:24.559986Z",
            "url": "https://files.pythonhosted.org/packages/36/ce/f5aab2332d927f8b300517ae186d31199f569768fb153f909e73042918df/safelib-0.6.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "59d7433f939d4691b2a2501daa65339dede927e1caa1fc84c2d64ffdc11dbd76",
                "md5": "86ab47984c67d51c889a8081a0cc317c",
                "sha256": "08bd3b8781a85cf91c5d7f486840398cec2836f7773f1f52d1fb80401bd5cc7a"
            },
            "downloads": -1,
            "filename": "safelib-0.6.1.tar.gz",
            "has_sig": false,
            "md5_digest": "86ab47984c67d51c889a8081a0cc317c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 4696,
            "upload_time": "2025-08-02T16:27:25",
            "upload_time_iso_8601": "2025-08-02T16:27:25.745642Z",
            "url": "https://files.pythonhosted.org/packages/59/d7/433f939d4691b2a2501daa65339dede927e1caa1fc84c2d64ffdc11dbd76/safelib-0.6.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-02 16:27:25",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "fswair",
    "github_project": "safelib",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "safelib"
}
        
Elapsed time: 0.42185s