This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Install and access data files (conf, json, sqlite3, ...) in an easy way.

Project Description

datafolder is a small python library that makes it very easy to install the data files of your package and access them later.

If you want to install some data files (conf, sqlite, csv, …) to a place like the user’s home directory and find it difficult with setuptools, then here is some help.

WARNING this is beta software!

First, let’s make life easier and use some ‘configuration by convention’.

I assume that (1) you have layout your project like:
    ├── mypkg.conf
    ├── mypkg.db
    └── ...

And that (2) you want to put a folder, in the home directory of the user (in Windows will be in %APPDATA%), with your data files (conf, csv, …) inside. This folder will have the name of your package (preceded with a ‘.’ in UNIX systems), let’s say ‘.mypkg’ and, of course, with the right permissions (it will work with sudo pip install mypkg). For virtual environements the data folder will be put at the root of the environement.

How to do it?

  1. First, install the datafolder package:

    $ pip install -U datafolder
  2. Then, type:

    $ datafolder

    It will make a file called that you must put inside your mypkg directory and a new file called that you must put in the root of your project.

  3. is a template that you have to adapt to your case:

import sys
import pkg_resources

from setuptools import setup

from mypkg.bootdf import Installer                         # <-- ADAPT THIS

# write the name of the package (in this case 'mypkg'!)
MYPKG = 'mypkg'                                            # <-- ADAPT THIS

# list of data files in mypkg (just the names)
# [don't forget to include these files in!]
MYDATAFILES = ['mypkg.conf', 'mypkg.db']                   # <-- ADAPT THIS

# tell setup were these files are in your package
# (I assume that they are together with the first
MYRESOURCES = [pkg_resources.resource_filename(MYPKG, datafile)
               for datafile in MYDATAFILES]

# now, create the installer
installer = Installer(sys.argv)

# create the data folder and tell setup to put the data files there
DATAPATH = installer.data_path(MYPKG)
data_files = [(DATAPATH, MYRESOURCES)]

# now, setup can do his thing...
    packages=[MYPKG,'other_packg1','other_packg2'],        # <-- ADAPT THIS
    ...                                                    # <-- ADAPT THIS

# but we are NOT READY, in some cases the data files
# don't have the appropriate permissions,
# let us fix that...
  1. Now, rename the file to
  2. Write your file (missing this step is the cause of many problems!). Should look like this:
include *.txt
include *.md
include *.rst
include mypkg/*.conf
include mypkg/*.rst
include mypkg/*.db

And that is all!

But with version 0.2.1 it is even better!
  1. Just go to the root of you project and in a terminal type:

    $ datafolder mypkg
  2. Now, you will see that and were fill in for you and is already inside the mypkg folder. You only need to complete as need (the fields author, email, url and trove classifiers …).

“But, I have the reverse problem, how can I access these files in my code?” I heard you say.

Very easy, in your code (for a file in the same folder as

from .bootdf import DataFolder

data = DataFolder('mypkg')

# now you can get the full path of each data file, e.g.
conf_fp = data.files['mypkg.conf']

# do your thing... (read, write, ...)

For your convinience, the DataFolder class discovers the location of the data folder for you and provides attributes and methods, that make it easy to handle the files presente in the data folder.

Feedback, please!

REMARK: as you can see above, this only works if the install method uses Is not the case of python wheels however!
Release History

Release History

This version
History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
datafolder-0.3.6-py2.py3-none-any.whl (9.9 kB) Copy SHA256 Checksum SHA256 2.7 Wheel Mar 16, 2015
datafolder-0.3.6.tar.gz (9.7 kB) Copy SHA256 Checksum SHA256 Source Mar 16, 2015

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting