Package: rezzie
rezzie: A small library for accessing resources and data shipped with your
package without using the pkg_resources API.BackgroundShipping data files with your Bioinformatic Python packages is a typical pattern. There are several ways of accessing these data files, but they can be cumbersome and error-prone. One common approach often recommended on StackOverflow is to use the module's__file__attribute to find the path of the running script and, from there, find the relative path to the resource. But, this approach is fragile and can easily break if the resource is moved, and it doesn't deal with the case where the resource is in a zip file. Another approach is to use thepkg_resourcesAPI. But, that module is substantial and has a lot of dependencies, which can cause significant startup times for your command-line tools.A third-party package calledimportlib_resourcesprovides a nice API to deal with this problem, and in more recent versions of (Python ≥3.9), it has become part of the standard library and is built on theimportlib.resourceAPI of the standard library.Here, we provide a simple library that has a single function to access the path to any resource shipped with your package. The function returns apathlib.Pathobject. You can then read the contents of the file, pass it to a subprocess routine, or do anything else you may need or want  to do.
We have made it so that it transparently supports versions of Python ≥3.7. When using versions of Python ≥3.9, it uses the standard libraryimportlib_resourcesAPI. Otherwise, it uses theimportlib_resourcespackage. It will only install theimportlib_resourcespackage if the Python version requires it. So, it should keep things lean if you use a recent Python version.For that reason and many more, we recommend using Python ≥3.10. There are significant performance improvements in the standard library importlib API and notable performances in Python overall to warrant the upgrade.InstallationYou can installrezziefrom PyPI usingpip:pipinstallrezzieUsageTo userezzie, you need to have a package that has resources that you want to
access. For example, let's say you have a package calledmy_packagethat has
a resource calledmy_resource.txtin a folder calleddata, that you want to
access. You can do that using therezzieAPI as follows:fromrezzieimportget_pathresource_path=get_path("my_package","data","my_resource.txt")Theget_pathfunction takes two arguments: the name of the package, and the
path and name of the resource.ExampleLet's say you have a package calledmy_packagethat has a resource calledmy_resource.txtin a folder calleddata, that you want to access.Themy_packagepackage has the following structure:my_package├──__init__.py├──data│└──my_resource.txt└──__main__.pyYourpyproject.tomlfile should look like this to ensure the data files are
packaged correctly (this assumes usingsetuptoolsas the build backend):[build-system]requires=["setuptools>=42","wheel"]build-backend="setuptools.build_meta"[project]name="my_package"[tool.setuptools]include-package-data=true[tool.setuptools.package-data]my_package=["*.txt"]Themy_package/__init__.pyfile should look like this:fromrezzieimportget_pathresource_path=get_path("my_package","data","my_resource.txt")AuthorAnders Goncalves da Silva (@andersgs)