14

Is it possible to include a csv file as part of python package?

I am creating a package and want some default config files which are imported at runtime.

I know I can store as a list or other structure in a .py file, but this will break the pattern I'm building against.

Ammar Akhtar
  • 1,698
  • 3
  • 13
  • 25

2 Answers2

16

This can be done in a two-step process, as detailed here.

You need one file in the root of your source, MANIFEST.in which reads:

include path/to/yourfile.csv

and you also need to add include_package_data=True, to the setup() function in setup.py. Tried and tested.

TheChymera
  • 17,004
  • 14
  • 56
  • 86
1

I guess that you may use a specific module more than an "homemade version" to store configuration. In your case: The Python standard library includes the ConfigParser module, which handles ini-style configuration files for you.

A. STEFANI
  • 6,707
  • 1
  • 23
  • 48