python-muckrock

A simple Python wrapper for the MuckRock API

Getting started

Installation is as easy as:

pip install python-muckrock

Usage

Import the MuckRock client and initialize it.

from muckrock import MuckRock

client = MuckRock()

Request all of the latest FOIA requests.

request_list = client.foia.latest()

Request the latest completed FOIA requests.

request_list = client.foia.filter(status="done")

Request a particular FOIA request by its identifier.

request = client.foia.get(100)

JSON is returned.

Authentication

To authenticate with the MuckRock API, simply supply your API token when you instantiate the MuckRock client. This will you allow you to do things like access your embargoed requests.

import os
from muckrock import MuckRock

client = MuckRock(token="YOUR TOKEN")

Rather than putting your token in your code, consider storing the token in something an environmental variable and using that to authenticate with the API. Anything exported with MUCKROCK_API_TOKEN will be automatically used by the client.

Creating requests

Once you’ve authenticated, you can create an information request by passing in a title, agency id and document request to the create method.

client.foia.create(
    agency_ids=248,
    title="API Test File Request",
    document_request="I would like the government's secret receipe for the world's best burrito.",
)

Other resources