Python pip data_files

I’m currently trying to create a package for my python project GitHub - ZerataX/matrix-registration: a token based matrix registration api
And creating an expression to install this package is fairly simple, except for
the data_file option in to ship a sample configuration file.
My python project later reads from this sample file if no configuration is found.

Usually with others distros I just looked at what python gave me with sys.prefix() or just __location__

but nix puts this file here:


And I’m wondering if there is a smart way for me to find this place from my python application, instead of doing something like

__location__ + "../../../config/config.sample.yaml"

Furthermore I would like to develop a module to configure this package later. So my second question would be if this location where the sample config is currently put is also a good place to put the final configuration file that I would create with my module?

from 2. Writing the Setup Script — Python 3.10.0 documentation

The directory should be a relative path. It is interpreted relative to the installation prefix (Python’s sys.prefix for system installations

The prefix is the store path. Looking at your it would install it in /config/config.sample.yaml, that does not every seem to be a good place.

Check importlib.resources (standard library) and alternatively pkg_resources (setuptools).

yes I’ve read that and already tried using prefix, but this is the store path to my python install not to my python package, so something like

And importlib.resources points to /nix/store/xxx-python3.7-matrix-registration-0.5.6/lib/python3.7/site-packages/matrix_registration/config.sample.yaml
instead of

so pretty much the same as what I get with using __location__