Skip to main content

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 ResourceMap object 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
If encoding is not specified in load_json() or load_yaml(),
charset-normalizer will 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

resourcemap-0.0.1.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

resourcemap-0.0.1-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

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

Hashes for resourcemap-0.0.1.tar.gz
Algorithm Hash digest
SHA256 34ce8e3ad51a933efdcf106ecf4917251a7635378ebaca447ae3980bb7b83f60
MD5 9f5af1ece141eb14a844e59bf2eca71d
BLAKE2b-256 5df87eed396e68846949c4887598462741b73234769722386b644f440fba41a0

See more details on using hashes here.

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

Hashes for resourcemap-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 13311c97e4080338438fd28027cd467b823c6528220ae153f88a404f2772a754
MD5 d22518aa5c293041c144ac8db7a393b7
BLAKE2b-256 29eea45261f4cd080d26976d2490a1cc69e4feee274f00ec37c743b2175b6de1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page