Skip to main content

An example project demonstrating various ways to access data files in Python package

Project description

This project shows how to package data files within a Python distribution, and has some example code for reading the data files. To build this distribution, create a venv with setuptools, wheel, and pep517 installed, then execute the latter as a module:

python -m pep517.build .

The distributions (an sdist .tar.gz and a bdist .whl) will be written to ./dist/ subdirectory. To test it out, install the distribution and run the console script resources-example.

Here’s a compatibility summary of the five approaches demonstrated:

Module Description In stdlib? Works on Py2? Works on Py3? Works in zipfile?
example1.py os.path.join yes yes yes no
example2.py pkgutil yes yes yes yes
example3.py pkg_resources no yes yes yes
example4.py importlib.resources yes no yes (3.7+) yes
example5.py importlib_resources no yes yes yes

If you are interested in creating an executable zip from source, you can use stdlib zipapp utility (Python 3.5+):

python3 -m zipapp --compress /path/to/resources-example --main="myapp:main" --output=myapp.zip

And now you can run the zip directly with the interpreter (any Python version):

python myapp.zip

Project details


Download files

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

Files for resources-example, version 0.2
Filename, size File type Python version Upload date Hashes
Filename, size resources_example-0.2-py2.py3-none-any.whl (5.7 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size resources-example-0.2.tar.gz (4.8 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page