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

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: local_resources-1.0.2.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.2.tar.gz
Algorithm Hash digest
SHA256 4545cd2170767a20403c70ecac4b36089564965f2151d3eaf80e3ac6dbd954c1
MD5 6bce24ec0c8d7c88c5753a11b83cc293
BLAKE2b-256 bf1715a6dbfbbb84b6e658ba49c072e87c0d35f1d57b0c54de0c5632b474565a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: local_resources-1.0.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7e22517ab88d6a93d4ddf799050cd82d2c1e7d308d9acb8442ff3bddb15c4613
MD5 a75795cb27dbdc7928081eda521db1bf
BLAKE2b-256 add116c197fa3fafa5b44be2d7bc9492fe0428f92b1254907c84df8e489d715f

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