|
shimport
|
|
| Import utilities for python | |
Overview
Import utilities for python
Installation
See pypi for available releases.
pip install shimport
Usage
Simple lazy modules
>>> import shimport
>>> pathlib = shimport.lazy('pathlib')
>>> print(pathlib.Path('.').absolute)
<bound method Path.absolute of PosixPath('.')>
>>>
Filtering module contents
Filtering for Public Functions
Suppose you want to retrieve just the function-definitions from a module namespace.
Using shimport.wrapper let's you slice and dice:
>>> import shimport
>>> wrapper = shimport.wrapper("os.path")
>>> wrapper = wrapper.prune(only_functions=True)
>>> print(wrapper.namespace.keys())
dict_keys(['abspath', 'basename', 'commonpath', 'commonprefix', 'dirname', 'exists', 'expanduser', 'expandvars', 'getatime', 'getctime', 'getmtime', 'getsize', 'isabs', 'isdir', 'isfile', 'islink', 'ismount', 'join', 'lexists', 'normcase', 'normpath', 'realpath', 'relpath', 'samefile', 'sameopenfile', 'samestat', 'split', 'splitdrive', 'splitext'])
>>>
Filtering using Chaining / Fluid Style
Some use-cases for shimport involve scenarios that aren't great with declarative-style development.
So, there's good support for chaining (aka fluent) programming style as you can see below. (Note that indention here follows fluent-style that shed/black should support)
>>> import shimport
>>> (
... shimport
... .wrapper('os.path')
... .prune(only_data=True)
... .prune(val_predicate=lambda v: v=='/')
... .namespace.keys()
... )
dict_keys(['sep'])
>>>
>>> import typing, shimport
>>> (
... shimport
... .wrapper("os.path")
... .prune(
... exclude_private=True,
... filter_module_origin=True)
... )
<ModulesWrapper[os.path]>
>>>
Filtering for Classes
Grab only the classes from the given namespace:
>>> import shimport
>>> namespace=shimport.wrapper('pathlib').filter(only_classes=True)
>>> assert 'Path' in namespace
# Grab only subclasses of a given class from the given namespace
#>>> plugins = shimport.wrapper('my_app.plugins').prune(...)
#>>>
Filtering for Data
Grab only the classes from the given namespace:
>>> import shimport
>>> namespace = shimport.wrapper('os.path').filter(only_data=True)
>>> assert 'sep' in namespace
>>>
Metadata
Release files for shimport 2024.3.12.9.59
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 |
|---|---|---|---|---|
| shimport-2024.3.12.9.59.tar.gz | 11.0 kB | Without provenance | Details for shimport-2024.3.12.9.59.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| shimport-2024.3.12.9.59-py3-none-any.whl | Python 3 | none | any | Details for shimport-2024.3.12.9.59-py3-none-any.whl |
Total release size: 23.2 kB
Release files / shimport-2024.3.12.9.59.tar.gz
| Download URL | shimport-2024.3.12.9.59.tar.gz |
|---|---|
| Size | 11.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1439bcb6d619ae63306a4c64662946aa5a1c0244a1fcb2f80f12a903d58c8127
|
|
BLAKE2b-256 checksum How to use checksums |
c4d6b28bc71ff397503882fbc5eb9f451e94786424a9007bced41a4a9e19b3ac
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.9.18
|
Release files / shimport-2024.3.12.9.59-py3-none-any.whl
| Download URL | shimport-2024.3.12.9.59-py3-none-any.whl |
|---|---|
| Size | 12.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5c6d5365aea4064ab001e4b8de579fbe03daf280cd4c6b2a568654faf8af6834
|
|
BLAKE2b-256 checksum How to use checksums |
02a193b520ca738710a25031d071764619a87dfd3cabdc40fb191121d9a37cc5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.9.18
|
Security for shimport 2024.3.12.9.59
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.