SkillAgentSearch skills...

OpenFEC

The first RESTful API for the Federal Election Commission. We're aiming to make campaign finance more accessible for journalists, academics, developers, and other transparency seekers.

Install / Use

/learn @fecgov/OpenFEC
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

Develop CircleCI Test Coverage

Master Test Coverage

package.json Known Vulnerabilities requirements.txt Known Vulnerabilities flyway Known Vulnerabilities

About this project

The Federal Election Commission (FEC) releases information to the public about money that's raised and spent in federal elections — that's elections for US President, Senate, and House of Representatives.

Are you interested in seeing how much money a candidate raised? Or spent? How much debt they took on? Who contributed to their campaign? The FEC is the authoritative source for that information.

The new FEC.gov aims to make campaign finance information more accessible (and understandable) to all users.

This repository, openFEC, is home to the FEC’s API

All FEC repositories:

  • FEC: a general discussion forum. We compile feedback from the FEC.gov feedback widget here, and this is the best place to submit general feedback.
  • openFEC: the first RESTful API for the Federal Election Commission
  • fec-cms: this project's content management system (CMS)
  • fec-proxy: this is a lightweight app that coordinates the paths between the web app and CMS

Get involved

We welcome you to explore, make suggestions, and contribute to our code.


Set up

We are always trying to improve our documentation. If you have suggestions or run into problems please file an issue!

Project prerequisites

  1. Ensure you have the following requirements installed:

    • Python (the latest 3.11 release, which includes pip and a built-in version of virtualenv called venv).

    • The latest long term support (LTS) or stable release of Node.js (which includes npm)

    • PostgreSQL (the latest 13 release).

    • Opensearch 2.11 (instructions here)

    • Flyway 12.1.1 (homebrew instructions)

      • After downloading, create a .toml file in the following location: flyway-12.1.1/conf/flyway.toml and set the flyway environment variables environment, url, user, password andlocations as

        [environments.local]
        url = "jdbc:postgresql://localhost:5432/cfdm_test"
        user = "<your local database username>"
        password = "<your local database password>"
        
        [flyway]
        environment = "local"
        locations = ["filesystem:/Users/<user>/<project>/api/openFEC/data/migrations"]
        
        

        to enable connection to a local database (e.g., cfdm_test from Create a test database, below) and specify the location of the database migration files (SQL)

    • See Database migrations for more information on installing and configuring flyway

  2. Set up your Node environment— learn how to do this with our Javascript Ecosystem Guide.

  3. Set up your Python environment— learn how to do this with our Python Ecosystem Guide.

  4. Clone this repository.

Project dependencies

Install project requirements

Use pip to install the Python dependencies:

pip install -r requirements.txt
pip install -r requirements-dev.txt

Use npm to install JavaScript dependencies:

nvm use --lts
npm install
npm run build
Git hooks

This repo includes optional post-merge and post-checkout hooks to ensure that dependencies are up to date. If enabled, these hooks will update Python dependencies on checking out or merging changes to requirements.txt. To enable the hooks, run:

invoke add-hooks

To disable, run:

invoke remove-hooks

Create a test database

In order to run tests locally, you'll need a test database.

To create the test database, run:

createdb cfdm_unit_test

Create a development database

Before you can run this project locally, you'll need a development database.

To create the development database, run:

createdb cfdm_test

Set the environment variable SQLA_SAMPLE_DB_CONN to point to this database, using:

export SQLA_SAMPLE_DB_CONN="postgresql://<username>:<password>@localhost:<port - default is 5432>/cfdm_test"

Load our sample data into the development database (cfdm_test) by running:

invoke create-sample-db

This will run flyway migrations on the empty database to create the schema, and then load sample data into this database from data/sample_db.sql.


Connecting to a RDS DB instance instead of local DB

Note: FEC members can set the SQL connection to one of the RDS boxes with:

export SQLA_CONN=<psql:address-to-box>

Warning: never perform 'update all' when pointing to an RDS box via the SQLA_CONN env var

Note: An additional setting for connecting to and utilizing mirrors/replica boxes can also be set with:

export SQLA_FOLLOWERS=<psql:address-to-replica-box-1>[,<psql:address-to-replica-box-2>,...]

Note: This is a comma separated (with no spaces) string that contains one or more connection strings to any replicas/mirrors that are setup.

Reach out to a team member to get the actual addresses for all of these connections.

Set other environment variables

  1. Run:

    export FEC_WEB_DEBUG=true
    

    This shows error details and more verbose request logging.

  2. Run:

    export FEC_API_URL=http://localhost:5000
    export FEC_CMS_URL=http://localhost:8000
    

    These are the default URLs to the other local FEC applications. For complete set-up instructions, explore our documentation for fec-cms.

    Note: If you modify your local environment to run these applications at a different address, be sure to update these environment variables to match.

  3. If you do not login to CloudFoundry with SSO (single sign-on), run:

    export FEC_WEB_USERNAME=<username_of_your_choosing>
    export FEC_WEB_PASSWORD=<password_of_your_choosing>
    

    Create these account credentials to gain full access to the application. You can set them to any username and password of your choosing.

    Note: FEC team members will also have additional environment variables to set up. Please reach out to a team member for detailed information.

  4. If you are using database replicas/mirrors you can also restrict connections to them to be asynchronous tasks only by running:

    export SQLA_RESTRICT_FOLLOWER_TRAFFIC_TO_TASKS=enabled
    

Run locally

Follow these steps every time you want to work on this project locally.

  1. Set the FLASK_APP environment variable to specify how to load the application. Flask is used when running the project locally, so you will want to turn the debugger on as well. If you'd like to run in development mode (reloader will trigger whenever your code or imported modules change and debugger is on by default) you can set FLASK_ENV=development. Pyenv-dotenv should set these for you automatically by reading .flaskenv.

    export FLASK_APP=webservices.rest
    export FLASK_DEBUG=1
    
  2. If you are using the legal search portion of the site, you will need OpenSearch running. Navigate to the installation folder (eg., opensearch-2.11.x) and run:

    cd bin
    ./opensearch \
      -E plugins.security.disabled=true
    

    NOTE: You can also disable security in your opensearch.yml file in your local opensearch

  3. Start the web server:

    flask run
    

    or

    python cli.py run
    
  4. View your local version of the site at http://localhost:5000.

Task queue

We use Celery to schedule periodic tasks— for example, refreshing materialized views and updating incremental aggregates. We use Redis as the Celery message broker.

To work with Celery and Redis locally, install Redis and start a Redis server. By default, we connect to Redis at `redis://localhost:637

View on GitHub
GitHub Stars529
CategoryFinance
Updated6d ago
Forks114

Languages

Python

Security Score

80/100

Audited on Mar 31, 2026

No findings