Python package that allows you to use application resources without worrying about where they are stored.
Project description
resourcemap
resourcemap is a Python package that allows you to use application resources without worrying about where they are stored.
It provides convenient APIs to load, locate, and manage resource files across different operating systems.
✨ Features
- Load JSON, YAML, or other files with automatic encoding detection (
charset-normalizer) - Define relocatable resource paths per application and author
- Automatically resolve resource locations based on user OS conventions
- Reuse a single
ResourceMapobject throughout your application
🚀 Installation
pip install resourcemap
📖 Usage
1. Basic Example
Load a file directly:
import resourcemap as resmap
# Direct load
file = resmap.load_json('path/to/file')
# Using a custom loader
file = resmap.load('path/to/file', loader=your_loader)
Note
Ifencodingis not specified inload_json()orload_yaml(),
charset-normalizerwill be used to automatically guess the encoding.
2. Automatic Resource Mapping
from pathlib import Path
import resourcemap as resmap
# Define your application info
APP = 'app_name'
AUTHOR = 'author_name'
# Save the default dictionary
resmap.ResourceMap.create(APP, AUTHOR) \
.set('config.json', 'path/to/config.json') \
.set('query.sql', 'path/to/query.sql') \
.set('data.csv', 'path/to/data.csv') \
.save(exist_ok=True)
# Automatic resource selection
config = resmap.load_json('config', APP, AUTHOR)
query = resmap.load_json('query', APP, AUTHOR, default=Path('default/path/to/query'))
# Get only the path without loading
data_path = resmap.locate('data', APP, AUTHOR)
resourcemap saves the dictionary of resource paths in an OS-appropriate location.
For example, on Windows:
%LocalAppData%\AUTHOR\resmap\APP.json
This file specifies where relocatable resources should be placed.
By default, create it using ResourceMap.create(), .set(), and .save().
3. Application-wide Usage
In most cases, a single ResourceMap instance is sufficient.
Load it once and reuse it across the entire app.
# app/path/to/resmap.py
import resourcemap as resmap
# Load the RESMAP used throughout the application
RESMAP = resmap.ResourceMap.load(APP, AUTHOR)
# app/path/to/your_code.py
from pathlib import Path
import resourcemap as resmap
from app.path.to.resmap import RESMAP
config = resmap.load_json('config', RESMAP)
query = resmap.load_json('query', RESMAP, default=Path('default/path/to/query'))
data_path = resmap.locate('data', RESMAP)
📦 Dependencies
📝 License
Apache License 2.0
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 resourcemap-0.0.1.tar.gz.
File metadata
- Download URL: resourcemap-0.0.1.tar.gz
- Upload date:
- Size: 9.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
34ce8e3ad51a933efdcf106ecf4917251a7635378ebaca447ae3980bb7b83f60
|
|
| MD5 |
9f5af1ece141eb14a844e59bf2eca71d
|
|
| BLAKE2b-256 |
5df87eed396e68846949c4887598462741b73234769722386b644f440fba41a0
|
File details
Details for the file resourcemap-0.0.1-py3-none-any.whl.
File metadata
- Download URL: resourcemap-0.0.1-py3-none-any.whl
- Upload date:
- Size: 9.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
13311c97e4080338438fd28027cd467b823c6528220ae153f88a404f2772a754
|
|
| MD5 |
d22518aa5c293041c144ac8db7a393b7
|
|
| BLAKE2b-256 |
29eea45261f4cd080d26976d2490a1cc69e4feee274f00ec37c743b2175b6de1
|