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.1.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

local_resources-1.0.1-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: local_resources-1.0.1.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.5.0.1 requests/2.23.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.1

File hashes

Hashes for local_resources-1.0.1.tar.gz
Algorithm Hash digest
SHA256 71dd63598f304455082a0e7e3880bd1f8b01aff00e003ffe1f13f422ee10f24f
MD5 6311b7a022b750e53256e81d71a5305e
BLAKE2b-256 c0fed8d11ff0a0ca4da0e0bb2d466b5f7535c2e4283ecfb3fe7f08f53589a2f0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: local_resources-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.5.0.1 requests/2.23.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.1

File hashes

Hashes for local_resources-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 dcd9ac5ad4d267433a72e7dd2ae6aa5900598ea7172c2de9e678fe20a9210c37
MD5 8d6ef24bf1448dec96cddf9815a3308f
BLAKE2b-256 442aa8725d94e1cfd612002becf5965623186651559584da0c5becc9e29d1e74

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