View Source Census
Elixir library for interacting with the US Census API
installation
Installation
Add census
to your list of dependencies in mix.exs
:
def deps do
[{:census, "~> 0.2"}]
end
usage
Usage
Get an api key at api.census.gov/data/key_signup.html.
create-a-client
Create a client
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
query-the-api
Query the api
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.
license
License
This software is licensed under the Apache 2 License.