node-require
Like Node.js's require(), but with more supported file formats
Features
- Importing modules from higher folders
- Loading JSON, Toml, YAML and BSON files natively
- Easily extensible
Installing
Install base module:
# Linux / MacOS
python3 -m pip install -U require
# Windows
py -3 -m pip install -U require
Optional Dependencies
orjson: Faster JSON decodingujson: Alternarive fororjsontoml: Support for Tomlyaml: Support for YAMLbson: Support for BSON
Quick notes
This lib does not support importing builtin modules or site-packages (modules installed with pip).
Consider using usual import, or if you need a dynamic import, use Python's builtin importlib.import_module
Usage
Yeah, that's bad example, but i'm can't come up with a best one..
Example directory structure:
src/
tests/
test.py
config.json
regex.py
main.py
src/main.py:
import os
import importlib
for file in os.listdir('./tests'):
if file.endswith('.py'):
importlib.import_module(f'tests.{file[:-3]}').run()
src/regex.py:
import re
PWD = re.compile("[a-zA-Z0-9_\.]{12,16}")
src/config.json:
{
"user": {
"name": "Jonh",
"password": "Fluffy_Gim19"
}
}
src/tests/test.py:
from require import require
password_pattern = require('../regex.py').PWD
password = require('../config.json')['user']['password']
def run():
assert password_pattern.match(password) != None
Extending
See guide on this
Metadata
Release files for node-require 2.0.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 | Actions |
|---|---|---|---|---|
| node_require-2.0.1.tar.gz | 4.4 kB | Without provenance | Details for node_require-2.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| node_require-2.0.1-py3-none-any.whl | Python 3 | none | any | Details for node_require-2.0.1-py3-none-any.whl |
Total release size: 11.1 kB
Release files / node_require-2.0.1.tar.gz
| Download URL | node_require-2.0.1.tar.gz |
|---|---|
| Size | 4.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
657a7482743c7bfc0f2567345bd09d4106888488a7e8188832fa79e8aeabf11a
|
|
BLAKE2b-256 checksum How to use checksums |
367d0a8370c4856a6327be2f5f309657ac21a9b2af0a0cf00adc95f9356e1404
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.10.2
|
Release files / node_require-2.0.1-py3-none-any.whl
| Download URL | node_require-2.0.1-py3-none-any.whl |
|---|---|
| Size | 6.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
199b6a0ece641a402076dd0ac8f8940fa8e81f6cf1667a2923fd81ce7ca86aca
|
|
BLAKE2b-256 checksum How to use checksums |
4c1cd5b8e7a2047fae8421bcd7a65d32a741bd16f2c3f81b06584c5159d6225b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.10.2
|
Security for node-require 2.0.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.