python-require (repyrer)
Provides nodejs-style requiring of modules for python
This module allows imports of python modules using syntax similar to the node.js require
function. In particular, it takes string arguments comprised of (optionally) a
UNIX-style directory path and a module name, and returns a reference to the
loaded module. Specifying no directory path will have the module import
attempted first in the current working directory, then on the python path
variable (sys.path), allowing both local-to-the-folder imports and standard
library imports (as well as anything else you've configured into sys.path).
If an (absolute) directory path is included (i.e. a leading / in the directory path),
the module will first be attempted to be loaded from that directory first,
then the rest of the sys.path as a fallback. If a relative directory path
is provided (like lib/module_name or ../other_lib/module_name) the current
working directory is used to resolve the relative path.
NOTE: the leading ./ characters on a directory path (as in
./lib/module_name) indicate that the directory path should be resolved
relative to the current file NOT the current working directory. For example,
suppose you have the following file structure:
top_folder
|-----main.py
|-----lib
|-----A.py
|-----sub_lib
|-----B.py
Suppose main.py imports A.py as a module, and A.py in tern imports B.py
as a module. Inside of A.py, it should use B = repyre('./sublib/B'),
NOT B = repyre('sublib/B') since the latter will fail when main.py
imports A.py (because the current working directory will be top_folder
NOT lib). However, main.py is free to import A.py as A = repyre('lib/A')
or A = repyre('./lib/A') provided main.py will only ever be run directly
as a script from top_folder.
Example Usage
You can use repyrer exactly as you would import to access the standard library,
and anything else you might have pip installed:
>>> from repyrer import repyre
>>> os = repyre('os') # import standard library
>>> np = repyre('numpy') # import other libraries installed with pip, etc.
>>> plt = repyre('matplotlib.pyplot') # import sub-modules using '.' notation
You can also specify a directory path (relative to the current working directory, or absolute) preceding the module name to access local libraries, suppose you have a file structure like:
folder
|----CWD
|----main.py
|----adjacent_file.py
|----my_dev_lib
|-----module_A.py
|----my_other_lib
|-----module_B.py
Then, in the python shell
>>> adjacent = repyre('adjacent_file') # import other files relative to the CWD
>>> A = repyre('my_dev_lib/module_A') # import modules from a relative directory path (relative to CWD)
>>> B = repyre('../my_other_lib/module_B') # can use '..' in directory paths
And in a script like main.py:
from repyrer import repyre
adjacent = repyre('adjacent_file') # only works if script is run in this folder
adjacent = repyre('./adjacent_file') # safe to run from anywhere
Metadata
Release files for repyrer 0.4.0
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 |
|---|---|---|---|---|
| repyrer-0.4.0.tar.gz | 3.3 kB | Without provenance | Details for repyrer-0.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| repyrer-0.4.0-py3-none-any.whl | Python 3 | none | any | Details for repyrer-0.4.0-py3-none-any.whl |
Total release size: 8.5 kB
Release files / repyrer-0.4.0.tar.gz
| Download URL | repyrer-0.4.0.tar.gz |
|---|---|
| Size | 3.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
90ff5c646a232ba2f8e6feaa041b3db04104cc112ec83296e9dc54a486cd1ed8
|
|
BLAKE2b-256 checksum How to use checksums |
38cd63fe173c65596686fc9a03abf1fd03a221bd31ef7f1cb10f47cfd8b47861
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.0.post20201006 requests-toolbelt/0.9.1 tqdm/4.52.0 CPython/3.7.5
|
Release files / repyrer-0.4.0-py3-none-any.whl
| Download URL | repyrer-0.4.0-py3-none-any.whl |
|---|---|
| Size | 5.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f359173b1238755689e6f2268b5e4a72aacfc92c8c098983675663a65291b117
|
|
BLAKE2b-256 checksum How to use checksums |
dd0e5a2b522dee9db251d6104052dc50c5e0733843c8b068f850c378dd109af7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.0.post20201006 requests-toolbelt/0.9.1 tqdm/4.52.0 CPython/3.7.5
|
Security for repyrer 0.4.0
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.