data files

Date: January 22nd 2016
Last updated: January 25th 2016 provides metadata for your package. It can include information such as project data, text files, and extensions. Note there are only three required fields in, including name, version, and packages. Here I look at adding data files to a package for distribution.

1) The first option is to use a located inline with The sdist command looks for a to include in the final package.

2) The second option is to specify the files in that are required in the final package. In this example, I have added vowel_dataset.txt to the vowels package

3) The third option is to add text files or config files using the data_files command in


└── Project
        ├── LICENSE.txt
        ├──     # (1) inline with
        ├── README.txt
        ├── static
        |    └── data.txt   # (1) found by
        ├── rt
        |    ├── S1.txt     # (3) files included using data_files command
        |    └── S2.txt 
        └── vowels
             |    └── vowel_dataset.txt   # (2) package data
             ├── vowels.log

include Project/static/*
# Note that the following line is required in
# include_package_data = True

from setuptools import setup

    name = "vowels",
    version = "0.0.3",
    packages = ['vowels'],

    # use README.txt for the long description
    install_requires = ['logging'],

    # Include static files:
    # 1) Include during packaging
    include_package_data = True,

    # 2) Tell setuptools to package specific files
    package_data = {
        # If vowels package contains *.txt files, include them:
        'vowels': ['data/*.txt']},

    # 3) add addtional files 
    # ******(these need to be under version control)
    # installation directory = "random_text"
    # file names to include are in subdirectory "rt"
    # include two files
    data_files = [('random_text', ['rt/S1.txt', 'rt/S2.txt'])],

    # Metadata for registering ith Pypi        
    author = "Ray",
    author_email = "[email protected]",
    description = "Tools for manipulating vowels in a sentence",
    keywords = ["english","vowels"],
    url = "",   # project home page        


A set of tools for manipulating vowels in a sentence written \n
in english. 

Two methods are included; 
1) remove vowels in a sentence 
2) count the number of vowels in a sentence

The code:

"""Tools for manipulating vowels in a string."""
import logging
import doctest

# setup logging 
logging.basicConfig(filename='example.log', \
        format='%(asctime)s %(message)s', \
        datefmt='%m/%d/%Y %I:%M:%S %p', \
logger = logging.getLogger(__name__)

def count_vowels(sentence):
    Returns the number of vowels in a sentence.
    >>> count_vowels('testing this module with your text')
    count = 0 # set counter
    vowels = list('aeiou') # returns ['a','e','i','o','u']
    for letter in sentence: # loop over letters in the string
        if letter in vowels: # match letter to vowels
            count += 1 
        # add to a log file if logging enabled
        logging.debug('captured vowel: %s' %letter)
    # return the number of vowels
    return count

def remove_vowels(sentence):
    Removes all vowels in a sentence.
    >>> remove_vowels('testing out the removal of vowels')
    'tstng t th rmvl f vwls'
    removed_vowels = "".join([x for x in sentence if x not in list('aeiou')])
    return removed_vowels

# executed if run in the terminal: python
if __name__ == "__main__":
    import doctest, sys
    users_text = raw_input('enter text: ')
    print count_vowels(users_text)
    print remove_vowels(users_text)

results matching ""

    No results matching ""