Elixir library for interacting with the US Census API
Add census
to your list of dependencies in mix.exs
:
def deps do
[{:census, "~> 0.3"}]
end
Get an api key at api.census.gov/data/key_signup.html.
iex> client = Census.client(YOUR_API_KEY, dataset: "SF1", vintage: 2010)
Clients will default to the 2010 SF1 dataset. Other datasets are available at census.gov
Here, we're querying the total population for each county in Wisconsin. Documentation for available query parameters can be found at api.census.gov/data.html
iex> {:ok, resp} = Census.fetch(client, get: "NAME,H010001", foreach: "COUNTY:*", within: "STATE:55")
iex> resp.results
[%{"NAME" => "Adams County", "H010001" => "20875", ...}]
This library makes no attempt to coerce returned values. Almost everything is returned as a string, so you'll need to implement your own coercion if necessary.
This software is licensed under the Apache 2 License.