Skip to main content

Ability to fetch resources similar to Java Class.getResource()

Project description

Local Resources

This project is easy attempt to emulate Java's Class.getResource() method.

It provides simple access to files that are 'reachable' from directories and/or zip files referenced in PYTHONPATH.

Usage

Example:

from local_resources import Resource

with Resource("VERSION") as f:
    version = f.read()

It returns read-only file object in binary mode.

Aside of reading knowing files it provides 'list' method which is similar to os.listdir(path) with one caveat - directories are always returned with '/' appended:

from local_resources import Resource

files_and_dirs = Resource("").list()

for f in files_and_dirs:
    if f.endswith("myfiles/to_print_on_screen"):
        print(f"Do something with path {f}")
    else:
        with Resource(f) as file:
            print(f"File {f}:")
            print(file.read().decode('utf-8'))

Note: when list()' method is called there are no resources held after it finished, so there is no need for with` statement, nor cleaning up/closing resources at the end.

Note: for root of PYTHONPATH directories use """ or "/": Resource("").list().

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

local_resources-1.0.0.tar.gz (2.7 kB view details)

Uploaded Source

Built Distribution

local_resources-1.0.0-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file local_resources-1.0.0.tar.gz.

File metadata

  • Download URL: local_resources-1.0.0.tar.gz
  • Upload date:
  • Size: 2.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.7.3

File hashes

Hashes for local_resources-1.0.0.tar.gz
Algorithm Hash digest
SHA256 8d75a74d1dc692a6357d981d386b6aae2d38b2514239236160f2dbf13d0de39a
MD5 0b2e6d9972bf47dbc9b155e7305e7bea
BLAKE2b-256 ba9a7aa3181a53db12a55f616c834e52eb1a4da24ea9a9baa800b0f4c0a1ee69

See more details on using hashes here.

File details

Details for the file local_resources-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: local_resources-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.7.3

File hashes

Hashes for local_resources-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 39fbd13420a89411e01dec5f0ff36dcabeae6a164c24496ed58b39c2af7fdd27
MD5 d388c29879bd964777837a00891a2564
BLAKE2b-256 84175f5ba1788c046555e1b639bcbd674b4a88a217f43100817e1e54af8dcdc7

See more details on using hashes here.

Supported by

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