a small module for verifying an organization’s ability to accept charitable contributions in the U.S. via their EIN number.

If any of these imports work, you’re good to go. If none of them work, this module will still operate for you, but it will use the dumbdbm implementation, and could be much slower. Consider getting one of the above dbm implementations in python (dbhash is also deprecated and not included in python 3).

The module uses python’s anydbm module, so for performance reasons you should make sure that you have a fast implementation of the dbm format installed to which python has access. Simply try the following imports to check:

simple as that, you’re now good to go! But make sure to read on for (very important) notices about module useage and getting good performance.

basic useage

The following are the public functions make available by the module:

make_dbm ()

Downloads publication 78 from the IRS, unzips it, saves the txt to disk, then converts it into a dbm file for quick useage.

get_nonprofit_data ( ein , # the nonprofit organization's ein number optimize = False )

Given an EIN, retrieves the pipe delimited string data, "name|city|state|country|deductability code" from the local copy of publication 78 if the organization exists, otherwise it raises a key error.

If optimize=False , as by default, then it also checks to make sure the local copy of publication 78 is no more than 15 days out of date, calling make_dbm() if the data is more out of date than 15 days.

verify_nonprofit ( ein , # the nonprofit organization's ein number name = None , # name of the organization **as it appears in publication 78** city = None , # name of the city the organization is based in state = None , # state abbreviation for the organization deductability_code = None , # the deductability code of the organization # (see 'explanation of data and sources' in README.md) optimize = False )

takes data about the nonprofit organization as outlined in its call signature. The EIN must always be provided, all data should be given as strings. Every piece of information provided besides the EIN is optional. The function will take the provided non-None data, and check it against organizations in the database. If an organization is found matching the provided arguments, then verify_nonprofit returns true, else it returns false. The optimize parameter behaves the same as in get_nonprofit_data .

get_deductability_code ( ein , # the nonprofit organization's ein number name = None , # name of the organization **as it appears in publication 78** city = None , # name of the city the organization is based in state = None , # state abbreviation for the organization optimize = False )

takes data about the nonprofit organization as outlined in its call signature, the same as with verify_nonprofit except that it doesn’t accept a deductability code argument. Checks the provided data against organizations in the database, if a match is found, it returns the deductability code, if no match is found, it returns the empty string. The optimize parameter behaves the same as the optimize parameter for get_nonprofit_data .