Like Node.js's require(), but with more supported formats
Project description
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
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 node_require-2.0.1.tar.gz.
File metadata
- Download URL: node_require-2.0.1.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
657a7482743c7bfc0f2567345bd09d4106888488a7e8188832fa79e8aeabf11a
|
|
| MD5 |
d1b2edcd376f604429e89ff497e9751c
|
|
| BLAKE2b-256 |
367d0a8370c4856a6327be2f5f309657ac21a9b2af0a0cf00adc95f9356e1404
|
File details
Details for the file node_require-2.0.1-py3-none-any.whl.
File metadata
- Download URL: node_require-2.0.1-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
199b6a0ece641a402076dd0ac8f8940fa8e81f6cf1667a2923fd81ce7ca86aca
|
|
| MD5 |
12fa15419913d87758c2b87d868155f5
|
|
| BLAKE2b-256 |
4c1cd5b8e7a2047fae8421bcd7a65d32a741bd16f2c3f81b06584c5159d6225b
|