Import tools for python projects
Project description
|
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
>>>
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file shimport-2024.3.12.9.59.tar.gz.
File metadata
- Download URL: shimport-2024.3.12.9.59.tar.gz
- Upload date:
- Size: 11.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1439bcb6d619ae63306a4c64662946aa5a1c0244a1fcb2f80f12a903d58c8127
|
|
| MD5 |
021c2a039c668140831e709ba578612d
|
|
| BLAKE2b-256 |
c4d6b28bc71ff397503882fbc5eb9f451e94786424a9007bced41a4a9e19b3ac
|
File details
Details for the file shimport-2024.3.12.9.59-py3-none-any.whl.
File metadata
- Download URL: shimport-2024.3.12.9.59-py3-none-any.whl
- Upload date:
- Size: 12.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5c6d5365aea4064ab001e4b8de579fbe03daf280cd4c6b2a568654faf8af6834
|
|
| MD5 |
df3136a975bf65ef3e401ae43b7498aa
|
|
| BLAKE2b-256 |
02a193b520ca738710a25031d071764619a87dfd3cabdc40fb191121d9a37cc5
|