a small django app to verify information about nonprofits using their EINs
A django app for verifying U.S. nonprofits by their EIN number. For a general python module with similar functionality, check out charitycheck.
Visit the github.
pip install django-charitychecker
In your settings.py:
INSTALLED_APPS = ( ... charitychecker ... )
Note that if you want django-charitychecker to work properly, you’ll need to periodically fetch data from the IRS to update your local database.
django-charitychecker only checks U.S. based nonprofits, this means that it will not verify foreign nonprofits registered with the IRS (there are a few, but the data entry format for these organizations is inconsistent and so can’t be machine parsed easily).
django-charitychecker makes the following functions and models public:
a model representing a nonprofit with the following fields:
Of course, you can retrieve a nonprofit’s info using their EIN by IRSNonprofitData.objects.get(ein="some ein string").
A function which takes an iterator (it’s meant for file like objects but should take any iterator returning strings), and returns that iterator skipping all blank lines and stripping all white space from the end of any line.
A context manager taking two arguments, zip_url and file_name. The context manager downloads the file from zip_url, attempts to unzip and then return the file at the path file_name from the downloaded zip archive. It does all of this in memory without writing to disk.
A context manager for dealing with the IRS Publication 78 data. It automatically downloads, unzips, and opens the file from the IRS website, closing the resources when finished. It skips any FORGN registered nonprofits, and returns all of the nonprofit data strings as a generator. Use is as you would any context manager:
with IRSNonprofitDataContextManager() as irs_data: # code using irs_data as a file object ....
The Publication 78 file is a series of lines of the form ein|name|city|state|country|deductability_code.
A function that takes file_manager, convert_line, pk_field, and model arguments, then uses a file to update in bulk your application’s database. Specifically, it takes:
Note! This function will delete any data that is in your database and not present in the source file provided by file_manager.
A function that, when called, downloads a fresh copy of the IRS Publication 78 data, unzips it, and uses it to update the charitychecker database. It accepts no arguments.
A command that downloads a new copy of the IRS Publication 78 data, unzips it, and uses the data to update the charitychecker database.
This command takes no arguments, and only the default django command options. Run it by typing into the command prompt:
python manage.py update_charitychecker_data
Of course, you can only run the command after charitychecker is installed into your project’s settings.py file’s INSTALLED_APPS, and you’ve run python manage.py syncdb. This command could take a long time to finish, because it checks that your entire nonprofit database (800,000+ rows) is up to date.
Test the app as you would any other Django app. In a project with charitychecker installed run:
python manage.py test charitychecker
Note that since the test suite tests downloading and unzipping the data from the IRS, the test suite can take a minute or so, if you want to speed up the tests simply skip the tests using irs_nonprofit_data_context_manager and the test suite should run much faster.
Pull requests are welcome. Also check out charitycheck for a general python equivalent of this package if you are interested in contributing.
Suggestions for contributing: