Code Monkey home page Code Monkey logo

blsdata.jl's Introduction

BlsData

Build Status

A basic Julia interface to pull data from the Bureau of Labor Statistics using their Public API here.

Register a Public Data API account on the BLS website here to receive an API key. Then, take advantage of the increased daily query limit and other features.

Usage

Basic usage:

using BlsData
b = Bls()
one_series = get_data(b, "LNS11000000")
one_series_catalog = get_data(b, "LNS11000000"; catalog=true)
multiple_series = get_data(b, ["LNS11000000", "PRS85006092"])

Setup

Simply run

julia> Pkg.add("BlsData")

Functionality

The Bls type

The Bls type represents a connection to the BLS API.

Looks for a registration key in the file ~/.blsdatarc, or omits the registration key otherwise.

b = Bls()

Specify a registration key directly.

b = Bls(key="abc123")

Get and set fields.

api_url(b::Bls)                          # Get the base URL used to connect to the server
set_api_url(b::Bls, url::AbstractString) # Set the base URL used to connect to the server
api_key(b::Bls)                          # Get the API key
api_version(b::Bls)                      # Get the API version (v1 or v2) used
requests_made(b::Bls)                    # Get the number of requests made today
requests_remaining(b::Bls)               # Get the number of requests remaining today

Note that the requests made/remaining are calculated based on the lifetime of this object only and would not include those made in a distinct Julia session.

The BlsSeries type

The BlsSeries type contains the data in a query response.

id(s::BlsSeries)                         # Get series ID
series(s::BlsSeries)                     # Get data as DataFrame
catalog(s::BlsSeries)                    # Get joined catalog strings

Query data

Request one or multiple series from the BLS API.

get_data{T<:AbstractString}(b::Bls, series::Union{T,Array{T,1}};
               startyear::Int = Dates.year(now()) - QUERY_LIMIT + 1,
               endyear::Int   = Dates.year(now()),
               catalog::Bool  = false)
  • b: A Bls connection
  • series: A string, or array of strings, identifying the time series
  • startyear: A four-digit year identifying the start of the data request
  • endyear: A four-digit year identifying the end of the data request
  • catalog: Whether to return any available metadata about the series

Returns an object, or array of objects, of type BlsSeries.

Finding data series

The BLS mnemonics are somewhat obscure. You can attempt to build them programmatically by consulting this page.

Notes

The BLS API provides the following limits on requests:

v2 (registered) v1 (unregistered)
Daily query limit 500 25
Years per query limit 20 10
Series per query limit 50 25

BlsData.jl addresses these limits as follows:

  • track daily query limit for reference
  • make multiple requests under the hood, and concatenate results, for date ranges longer than limit
  • make multiple requests under the hood, and concatenate results, for lists of series longer than limit (TO BE IMPLEMENTED)

blsdata.jl's People

Contributors

micahjsmith avatar

Watchers

James Cloos avatar Grant Aarons avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.