import-proxy
a simple way to proxy imports in python
usage
proxy any object's attributes as a module:
from importproxy import register, object_resolver
class ApiClient:
def get_user(self, id): return f"user {id}"
def get_posts(self): return ["post1", "post2"]
client = ApiClient()
register('api', object_resolver(client))
from api import get_user, get_posts
print(get_user(123)) # user 123
create synthetic modules from dictionaries:
from importproxy import register, synthetic_module
math_funcs = {
'double': lambda x: x * 2,
'square': lambda x: x ** 2,
'PI': 3.14159
}
register('mymath', synthetic_module(math_funcs))
from mymath import double, PI
print(double(5)) # 10
proxy real modules with custom names:
from importproxy import register, proxy_module
import pathlib
register('paths', proxy_module(pathlib))
from paths import Path
p = Path('/tmp/test')
chain multiple sources together:
from importproxy import register, chain_resolvers, dict_resolver, proxy_module
import math
custom = {'triple': lambda x: x * 3}
register('math_2', chain_resolvers(
dict_resolver(custom), # try custom first
proxy_module(math) # fall back to real math
))
from math_2 import triple, sin
print(triple(4)) # 12 (custom)
print(sin(0)) # 0.0 (from math)
why does this exist?
i was tired of having to Thing = something.Thing when working with rpyc remote objects. now i can just from something import Thing and have my scripts work unmodified
yes, it's a massive hack, but it's funny, it amuses me
Metadata
Release files for import-proxy 0.1.1
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 | |
|---|---|---|---|---|
| import_proxy-0.1.1.tar.gz | 9.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| import_proxy-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.4 kB
Release files / import_proxy-0.1.1.tar.gz
| Download URL | import_proxy-0.1.1.tar.gz |
|---|---|
| Size | 9.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c44a2d1bd0f613cf4d2f930e4f9caf58769cc696ba621e5666d0521f13f7f8c2
|
|
BLAKE2b-256 checksum How to use checksums |
275d8c4f4fb801197d70b0b6b7a9eba6676bf8d5cb43454cb4ab9a8aac766aa9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.4 CPython/3.13.5 Darwin/24.6.0
|
Release files / import_proxy-0.1.1-py3-none-any.whl
| Download URL | import_proxy-0.1.1-py3-none-any.whl |
|---|---|
| Size | 3.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2504942a549a99b103182af3eea7f2e06f945ccd8c7205a8b58e96ebcde99d81
|
|
BLAKE2b-256 checksum How to use checksums |
05df4f6b0b91f2c234ef41ebe9d37260cd5e02cdd15c94ceaceb251b15f268c5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.4 CPython/3.13.5 Darwin/24.6.0
|
Security for import-proxy 0.1.1
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.