Skip to content
A simple python wrapper for the MuckRock API
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
muckrock
.coveragerc
.gitignore
.travis.yml
LICENSE
Makefile
README.md
requirements.txt
setup.cfg
setup.py
test.py

README.md

python-muckrock

A simple python wrapper for the MuckRock API

Still very much experimental and incomplete.

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 username and password when you instantiate the MuckRock client. This will you allow you to do things like access your embargoed requests.

>>> client = MuckRock(username="my_username", password="my_password")

When you authenticate with the MuckRock API, it supplies a token you can re-use. You can access that token by inspecting the token property of your client.

>>> client.token
'aaabbbcccdddeee111222333444555666777888fff'

Rather than putting your user name and password in your code, consider storing the token in something like an environmental variable, and using that to authenticate with the API.

>>> import os
>>> from muckrock import MuckRock
>>> client = MuckRock(token=os.environ['MUCKROCK_TOKEN'])

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."
)
You can’t perform that action at this time.