Skip to main content

a python parser for the .fec file format

Project description

This is still in very early testing. I wouldn't recommend relying on this library for anything important. That said, if you do try using it, I'd love to hear about it!

The goal of this project is to parse data in the .fec format and return a native python object. This is designed to work with either the bulk data zip files or from http requests like this and includes helper methods for both.

Installation

To get started, install from pypi by running the following command in your preferred terminal:

pip install fecfile

Usage (the hard way)


import fecfile

import json



with open('1229017.fec') as file:

    parsed = fecfile.loads(file.read())

    print(json.dumps(parsed, sort_keys=True, indent=2, default=str))

or:


import fecfile

import json

import requests



url = 'http://docquery.fec.gov/dcdev/posted/1229017.fec'

r = requests.get(url, headers={'User-Agent': 'Mozilla/5.0'})

parsed = fecfile.loads(r.text)

print(json.dumps(parsed, sort_keys=True, indent=2, default=str))

Note: the docquery.fec.gov urls cause problems with the requests library when a user-agent is not supplied. There may be a cleaner fix to that though.

Usage (the easy way)


import fecfile

import json



filing1 = fecfile.from_file('1229017.fec')

print(json.dumps(filing1, sort_keys=True, indent=2, default=str))



filing2 = fecfile.from_http(1146148)

print(json.dumps(filing2, sort_keys=True, indent=2, default=str))

Note the default=str parameter - that allows serializing to json dictionaries that contain datetime objects.

Developing locally

Assuming you already have Python3 and the ability to create virtual environments installed, first clone this repository from github and cd into it:


git clone https://github.com/esonderegger/fecfile.git

cd fecfile

Then create a virtual environment for this project (I use the following commands, but there are several ways to get the desired result):


python3 -m venv ~/.virtualenvs/fecfile

source ~/.virtualenvs/fecfile/bin/activate

Next, install the dependencies:


python setup.py

Finally, make some changes, and run:


python tests.py

Thanks

This project would be impossible without the work done by the kind folks at The New York Times Newsdev team. In particular, this project relies heavily on fech although it actually uses a transformation of this fork.

Contributing

I would love some help with this, particularly with the mapping from strings to int, float, and datetime types. Please create an issue or make a pull request. Or reach out privately via email - that works too.

To do:

Almost too much to list:

  • Handle files from before v6 when they were comma-delimited

  • create a dumps method for writing .fec files for round-trip tests

  • add more types to the types.json file

  • elegantly handle errors

Project details


Download files

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

Source Distribution

fecfile-0.3.4.tar.gz (16.6 kB view details)

Uploaded Source

Built Distribution

fecfile-0.3.4-py3-none-any.whl (17.0 kB view details)

Uploaded Python 3

File details

Details for the file fecfile-0.3.4.tar.gz.

File metadata

  • Download URL: fecfile-0.3.4.tar.gz
  • Upload date:
  • Size: 16.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.4.5

File hashes

Hashes for fecfile-0.3.4.tar.gz
Algorithm Hash digest
SHA256 87711e403c98929d7eb4cf1c9e79c62f949de64384f07552031700fd2d80dfb8
MD5 8905a593e935078f1e35e066da270308
BLAKE2b-256 019c1a5aa3b9685f011c7fed67abb82382b27d45e618af10eb88373b40a0ab59

See more details on using hashes here.

File details

Details for the file fecfile-0.3.4-py3-none-any.whl.

File metadata

  • Download URL: fecfile-0.3.4-py3-none-any.whl
  • Upload date:
  • Size: 17.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.4.5

File hashes

Hashes for fecfile-0.3.4-py3-none-any.whl
Algorithm Hash digest
SHA256 d52235e66cb096be77a8c11b397ec64047fd7b024aef23d7b5d747b5ef86ebed
MD5 717a828f8bb8c8c8e225abcba2f49b97
BLAKE2b-256 55072ba89e9e926552817d7ee36bb8276320053eb02e0dd8536d81fad1c431b9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page