Skip to content

US state legislatures

State legislators, committees, election returns, ideology scores, bills and roll-call votes

Connector software
Free and open source
Service credentials
Required
Use with an agent

Install the Orchard skill in your project to help your agent find connectors, configure them, and verify SQL results.

npx skills add Query-farm/vgi-skills --skill orchard

Copy this request into your coding agent to get started.

Use https://query.farm/products/orchard/connectors/us-state-legislatures/index.md to help me query US state legislatures with DuckDB or Haybarn 2.0.1 and VGI protocol 3.4. Ask only for missing details about the result I need or whether I want local execution, self-hosting or Query Farm hosting. Check the connector's actual hosting availability, credentials and input requirements. Read one format of each needed reference and the exact object declarations before writing SQL. Use a released connector, and distinguish a saved example result from anything you actually execute. If you cannot run the query, tell me what remains to verify.

Identifiers for Nebraska and North Carolina

Uses your connected account. Set up the connector and credentials to run it with your data.

SELECT state, state_fips, jurisdiction_id
FROM us_statelegs.main.states
WHERE state IN ('NE', 'NC')
ORDER BY state

Quick start

Choose where to run US state legislatures, then follow the steps below.

The connector runs alongside DuckDB or Haybarn. No Query Farm account is needed.

1. Install the vgi extension

Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.

setup.sql
SET allow_extension_repositories = 'allowed';

CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
    WITH PREFIX 'https://duckdb-extensions.query.farm';

INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;

2. Attach the connector

Attach with uvx

Needs uv. uvx builds the worker from its release tag on first attach and reuses the cached environment after that.

ATTACH 'us_statelegs' AS us_statelegs (
  TYPE vgi,
  LOCATION 'uvx --from git+https://github.com/Query-farm/[email protected] vgi-us-statelegs-worker'
);

3. Add service credentials

After attaching, create the secret for the service you want to query in the same SQL session. Replace the placeholders with your service settings.

openstates credentials

Open States API v3 key (free from Plural) for the os_* bill, vote, people, committee and event functions.

Get these credentials →
secret.sql
CREATE SECRET openstates (
    TYPE openstates,
    api_key '<OPENSTATES_API_KEY>'  -- secret
);
Credential fields and requirements →

4. Run a query

query.sql
SELECT state, state_fips, jurisdiction_id
FROM us_statelegs.main.states
WHERE state IN ('NE', 'NC')
ORDER BY state
More example queries →
Technical details
Verified connector release
v0.2.0
Engine
2.0.1
VGI protocol
3.4.0
Verified on
December 1, 2026
Release notes on GitHub
Pin a version for production

When running the connector yourself, keep a specific release until you’re ready to upgrade. Replace the ATTACH statement above with this one and follow the same extension and credential setup.

Attach with uvx

Needs uv. uvx builds the worker from its release tag on first attach and reuses the cached environment after that.

ATTACH 'us_statelegs' AS us_statelegs (
  TYPE vgi,
  LOCATION 'uvx --from git+https://github.com/Query-farm/[email protected] vgi-us-statelegs-worker'
);

Overview

US state legislatures in SQL: current and former state legislators, their terms and committee rosters from the Open States people data, state legislative election returns since 1967, Shor-McCarty legislator ideology scores, and live bills, votes and events from the Open States API.

ATTACH options

cache_dir
Directory for downloaded datasets (people ~5 MB, Klarner ~110 MB + Parquet, Shor-McCarty ~7 MB). Default: the per-user cache directory, e.g. ~/Library/Caches/vgi-us-state-legislatures.VARCHAR
max_age_days
Re-check the Open States people archive once the cached copy is this many days old.BIGINT
offline
Never download; use cached datasets only (a missing one fails).BOOLEAN
openstates_api_url
Base URL of the Open States API v3; override for a mirror or a test server.VARCHAR
openstates_min_interval
Minimum seconds between Open States API requests (free-tier rate limits).DOUBLE
people_archive_url
URL of the openstates/people repository tar.gz.VARCHAR
klarner_url
URL of the Klarner election returns tab file (Harvard Dataverse).VARCHAR
shor_mccarty_url
URL of the Shor-McCarty individual legislator tab file (Harvard Dataverse).VARCHAR
shor_mccarty_aggregate_url
URL of the Shor-McCarty chamber aggregate tab file (Harvard Dataverse).VARCHAR

Catalog

Everything us_statelegs exposes once attached — read straight from the worker's released build.

us_statelegs 1 schema
main 1 table · 16 functions

State legislators, terms, committees, election returns, ideology scores, and Open States API bills, votes and events.

Schema examples (17)
Examples (17)

Identifiers for Nebraska and North Carolina

SELECT state, state_fips, jurisdiction_id
FROM us_statelegs.main.states
WHERE state IN ('NE', 'NC')
ORDER BY state;

Party balance of the sitting North Carolina General Assembly by chamber

SELECT chamber, party, count(*) AS members
FROM us_statelegs.main.legislators(state := 'NC', current := true)
GROUP BY ALL
ORDER BY chamber, members DESC;

Ohio legislators who served in both chambers

SELECT person_id, name, count(DISTINCT chamber) AS chambers
FROM us_statelegs.main.legislator_roles(state := 'OH')
GROUP BY ALL
HAVING count(DISTINCT chamber) > 1
ORDER BY name
LIMIT 20;

The largest Nebraska Legislature committees and their chairs

SELECT name, chair, members
FROM us_statelegs.main.committees(state := 'NE')
WHERE classification = 'committee'
ORDER BY members DESC, name
LIMIT 10;
13 more examples

Nebraska senators with the most committee assignments

SELECT m.member_name, count(*) AS committees
FROM us_statelegs.main.committee_members(state := 'NE') m
GROUP BY ALL
ORDER BY committees DESC, m.member_name
LIMIT 10;

How often Wisconsin Assembly incumbents won their general elections, by year

SELECT year,
  round(avg(won::INT) FILTER (WHERE incumbent), 3) AS incumbent_win_rate
FROM us_statelegs.main.election_returns(state := 'WI', chamber := 'lower')
WHERE election_type = 'g'
GROUP BY year
ORDER BY year;

Texas House party medians by year: how far apart the parties are

SELECT year, party, round(median(np_score), 3) AS median_np
FROM us_statelegs.main.legislator_ideology(state := 'TX')
WHERE chamber = 'lower'
GROUP BY ALL
ORDER BY year, party;

The ten most polarized state legislative chambers in 2020

SELECT state, chamber, party_gap
FROM us_statelegs.main.chamber_ideology(first_year := 2020, last_year := 2020)
ORDER BY party_gap DESC
LIMIT 10;

Which datasets are cached, and under what licence

SELECT dataset, licence, cached, downloaded_at
FROM us_statelegs.main.cache_info()
ORDER BY dataset;

Pull the latest Open States people data now

SELECT dataset, status, bytes
FROM us_statelegs.main.refresh_cache('people');

The five states whose bill data were updated least recently

SELECT state, latest_bill_update
FROM us_statelegs.main.os_jurisdictions()
ORDER BY latest_bill_update
LIMIT 5;

North Carolina's five most recent sessions

SELECT session, name, start_date
FROM us_statelegs.main.os_sessions(state := 'NC')
ORDER BY start_date DESC
LIMIT 5;

North Carolina's current state senators by district

SELECT name, party, district
FROM us_statelegs.main.os_people(state := 'NC', chamber := 'upper')
ORDER BY district::INTEGER;

Ten recently passed Nebraska bills

SELECT identifier, title, latest_action_date
FROM us_statelegs.main.os_bills(state := 'NE', session := '109')
WHERE latest_passage_date IS NOT NULL
ORDER BY latest_action_date DESC
LIMIT 10;

Recent final-passage votes in the Nebraska Legislature

SELECT bill_identifier, motion_text, yes, no, result
FROM us_statelegs.main.os_votes(state := 'NE', session := '109')
WHERE 'passage' = ANY(motion_classification)
ORDER BY vote_date DESC
LIMIT 10;

The five largest North Carolina House committees

SELECT name, len(members) AS size
FROM us_statelegs.main.os_committees(state := 'NC', chamber := 'lower')
ORDER BY size DESC
LIMIT 5;

Upcoming North Carolina committee meetings

SELECT start_time, name, location_name
FROM us_statelegs.main.os_events(state := 'NC', after_date := '2026-01-01')
WHERE status <> 'cancelled'
ORDER BY start_time
LIMIT 10;
Tables
states 4 examples10 cols

The 50 state legislatures plus DC and Puerto Rico, with USPS, FIPS and Open States identifiers.

Columns
statenot null VARCHAR
USPS code, upper case ('NE').
state_fipsnot null VARCHAR
Two-digit state FIPS code, with leading zero ('31').
namenot null VARCHAR
State, district or territory name.
jurisdiction_idnot null VARCHAR
Open States / Open Civic Data jurisdiction id (ocd-jurisdiction/country:us/state:ne/government).
division_idnot null VARCHAR
OCD division id (ocd-division/country:us/state:ne).
legislature_namenot null VARCHAR
Official name of the legislative body ('Nebraska Legislature', 'Council of the District of Columbia').
unicameralnot null BOOLEAN
True for single-chamber bodies (Nebraska and the DC Council).
chambersnot null VARCHAR[]
Chamber codes used throughout this catalog: ['upper','lower'] or ['legislature'].
upper_chamber_name VARCHAR
Name of the upper chamber ('Senate'); NULL when unicameral.
lower_chamber_name VARCHAR
Name of the lower chamber ('House of Representatives', 'Assembly', 'House of Delegates'); NULL when unicameral.
ConstraintsPRIMARY KEY (state)
Examples (4)

Identifiers for Nebraska and North Carolina

SELECT state, state_fips, jurisdiction_id
FROM us_statelegs.main.states
WHERE state IN ('NE', 'NC')
ORDER BY state;

How many legislatures use each name for their lower chamber

SELECT lower_chamber_name, count(*) AS states
FROM us_statelegs.main.states
WHERE NOT unicameral
GROUP BY ALL
ORDER BY states DESC;

The unicameral legislatures

SELECT state, legislature_name
FROM us_statelegs.main.states
WHERE unicameral
ORDER BY state;
1 more example

How the lower chambers are named

SELECT lower_chamber_name, count(*) AS n
FROM us_statelegs.main.states
WHERE NOT unicameral
GROUP BY ALL
ORDER BY n DESC, lower_chamber_name;
Link
Table functions
cache_info () 1 example

What each runtime-downloaded dataset is, its licence, and whether it is cached locally

No arguments
Returns columns
dataset VARCHAR
Dataset key: people, klarner_election_returns, shor_mccarty_*.
description VARCHAR
What the dataset is.
licence VARCHAR
SPDX licence of the upstream data.
source_url VARCHAR
URL the file is (or would be) downloaded from.
source_page VARCHAR
Landing page / DOI of the dataset.
status VARCHAR
'missing', 'cached', or after a refresh 'downloaded'/'not_modified'/'stale'.
cached BOOLEAN
True when a verified copy is in the cache.
path VARCHAR
Path of the cached file.
bytes BIGINT
Size of the cached file.
sha256 VARCHAR
SHA-256 of the cached file.
downloaded_at TIMESTAMP WITH TIME ZONE
When the cached copy was downloaded.
checked_at TIMESTAMP WITH TIME ZONE
When upstream was last checked for a newer copy.
Example

Which datasets are cached, and under what licence

SELECT dataset, licence, cached, downloaded_at
FROM us_statelegs.main.cache_info()
ORDER BY dataset;
Link
chamber_ideology (first_year := BIGINT, last_year := BIGINT, state := VARCHAR) 2 examples

Shor-McCarty chamber and party ideology medians and polarization by state-chamber-year

Named arguments
first_year := BIGINT
Earliest year (data start in 1993). · default null
last_year := BIGINT
Latest year (data end in 2022). · default null
state := VARCHAR
Only this state: USPS code such as 'NE' (any case) or two-digit FIPS. NULL = all. · default null
Returns columns
state VARCHAR
USPS code, upper case.
state_fips VARCHAR
Two-digit state FIPS code.
year INTEGER
Year.
chamber VARCHAR
'upper', 'lower', or 'legislature' for Nebraska.
median DOUBLE
Whole-chamber median NP-score.
dem_median DOUBLE
Democratic party median NP-score.
rep_median DOUBLE
Republican party median NP-score.
majority_median DOUBLE
Majority party median NP-score.
minority_median DOUBLE
Minority party median NP-score.
dem_mean DOUBLE
Democratic party mean NP-score.
rep_mean DOUBLE
Republican party mean NP-score.
party_gap DOUBLE
Distance between the party medians: the authors' preferred polarization measure.
member_distance DOUBLE
Average distance between any two members: a party-free polarization measure.
dem_sd DOUBLE
Democratic heterogeneity.
rep_sd DOUBLE
Republican heterogeneity.
chamber_sd DOUBLE
Whole-chamber heterogeneity.
median_error DOUBLE
Bootstrapped standard error of the chamber median.
Examples (2)

The ten most polarized state legislative chambers in 2020

SELECT state, chamber, party_gap
FROM us_statelegs.main.chamber_ideology(first_year := 2020, last_year := 2020)
ORDER BY party_gap DESC
LIMIT 10;

Nebraska's unicameral Legislature drifting over time

SELECT year, median, party_gap
FROM us_statelegs.main.chamber_ideology(state := 'NE')
ORDER BY year;
Link
committee_members (state := VARCHAR) 2 examples

Current committee rosters: one row per member per committee (Open States people data)

Named arguments
state := VARCHAR
Only this state: USPS code such as 'NE' (any case) or two-digit FIPS. NULL = all. · default null
Returns columns
committee_id VARCHAR
Open States organization id of the committee.
committee_name VARCHAR
Committee name.
state VARCHAR
USPS code of the legislature, upper case.
chamber VARCHAR
Committee chamber: 'upper', 'lower' or 'legislature'.
person_id VARCHAR
Open States person id of the member, when matched.
member_name VARCHAR
Member name as listed on the roster.
role VARCHAR
Role on the committee: 'member', 'chair', 'vice chair', 'ranking member', .
Examples (2)

Nebraska senators with the most committee assignments

SELECT m.member_name, count(*) AS committees
FROM us_statelegs.main.committee_members(state := 'NE') m
GROUP BY ALL
ORDER BY committees DESC, m.member_name
LIMIT 10;

Committee chairs in North Carolina by party

SELECT l.party, count(*) AS chairs
FROM us_statelegs.main.committee_members(state := 'NC') m
JOIN us_statelegs.main.legislators(state := 'NC') l USING (person_id)
WHERE m.role = 'chair'
GROUP BY ALL
ORDER BY chairs DESC;
Link
committees (state := VARCHAR) 2 examples

Current state legislative committees and subcommittees from the Open States people data

Named arguments
state := VARCHAR
Only this state: USPS code such as 'NE' (any case) or two-digit FIPS. NULL = all. · default null
Returns columns
committee_id VARCHAR
Open States organization id.
state VARCHAR
USPS code of the legislature, upper case.
chamber VARCHAR
'upper', 'lower' or 'legislature'.
name VARCHAR
Committee name.
classification VARCHAR
'committee' or 'subcommittee'.
parent_id VARCHAR
Parent committee id, for subcommittees.
members INTEGER
Number of members on the roster.
chair VARCHAR
Name of the member whose role is 'chair'.
links VARCHAR[]
Committee web pages.
sources VARCHAR[]
Pages the roster was compiled from.
jurisdiction_id VARCHAR
Open States jurisdiction id.
Examples (2)

The largest Nebraska Legislature committees and their chairs

SELECT name, chair, members
FROM us_statelegs.main.committees(state := 'NE')
WHERE classification = 'committee'
ORDER BY members DESC, name
LIMIT 10;

How many committees each chamber has

SELECT state, chamber, count(*) AS committees
FROM us_statelegs.main.committees()
GROUP BY ALL
ORDER BY state, chamber;
Link
election_returns (chamber := VARCHAR, first_year := BIGINT, last_year := BIGINT, state := VARCHAR) 2 examples

State legislative election returns 1967-2016, one row per candidate (Klarner, CC0)

Named arguments
chamber := VARCHAR
'upper', 'lower' or 'legislature' (Nebraska). · default null
first_year := BIGINT
Earliest election year (1967-2016). · default null
last_year := BIGINT
Latest election year (1967-2016). · default null
state := VARCHAR
Only this state: USPS code such as 'NE' (any case) or two-digit FIPS. NULL = all. · default null
Returns columns
case_id BIGINT
Klarner caseid: unique id of the candidate-election-party line.
state VARCHAR
USPS code, upper case.
state_fips VARCHAR
Two-digit state FIPS code.
year INTEGER
Election year.
election_date DATE
Election date, when month and day are recorded.
chamber VARCHAR
'upper', 'lower', or 'legislature' for Nebraska.
district VARCHAR
District designation as on the ballot.
district_name VARCHAR
Alphabetic part of the district designation.
district_number INTEGER
Numeric part of the district designation.
geo_post INTEGER
Geographic sub-district post.
mmd_post INTEGER
Multimember-district post/position.
district_type INTEGER
Klarner dtype: 1 single-member.
district_seats INTEGER
Number of seats in the district.
seats_up INTEGER
Seats to be filled in this election.
election_type VARCHAR
Klarner etype: 'g' general, 'gs' special with general, 'ssg' special statewide general, 's' special, 'dp'/'rp' Democratic/Republican primary, 'ttp' top-two primary, 'la...' Louisiana, '...runoff'.
general BOOLEAN
True for general elections.
determines_seat BOOLEAN
Klarner deter: the winner sits at the start of the session.
term_years DOUBLE
Anticipated term length in years.
candidate VARCHAR
Standardized candidate name, lower case 'last, first m.'.
candidate_id BIGINT
Klarner candid: stable across a candidate's elections.
party VARCHAR
Simplified party: d, r, b.
caucus_party VARCHAR
One party per candidate-election-season.
party_detail VARCHAR
Detailed party label from the returns.
experience VARCHAR
Prior service: inc (incumbent), other (other chamber), pastinc, pastother, pastboth, none.
incumbent BOOLEAN
True when experience = 'inc'.
votes BIGINT
Votes for this candidate on this party line.
outcome VARCHAR
Klarner outcome: 'w' won, 'l' lost, 'r' advanced to runoff, 'na'.
won BOOLEAN
True when outcome = 'w'.
county_name VARCHAR
County, for returns broken down by county.
county_fips VARCHAR
Three-digit county FIPS code for county-level rows.
uncertainty VARCHAR
Klarner uncert: which variables are uncertain for this row.
Examples (2)

How often Wisconsin Assembly incumbents won their general elections, by year

SELECT year,
  round(avg(won::INT) FILTER (WHERE incumbent), 3) AS incumbent_win_rate
FROM us_statelegs.main.election_returns(state := 'WI', chamber := 'lower')
WHERE election_type = 'g'
GROUP BY year
ORDER BY year;

Seats won by party in Minnesota general elections since 2000

SELECT year, party, count(*) AS seats_won
FROM us_statelegs.main.election_returns(state := 'MN', first_year := 2000)
WHERE general AND won
GROUP BY ALL
ORDER BY year, party;
Link
legislator_ideology (first_year := BIGINT, last_year := BIGINT, state := VARCHAR) 2 examples

Shor-McCarty state legislator ideology scores, one row per legislator-year-chamber, 1993-2022

Named arguments
first_year := BIGINT
Earliest year (data start in 1993). · default null
last_year := BIGINT
Latest year (data end in 2022). · default null
state := VARCHAR
Only this state: USPS code such as 'NE' (any case) or two-digit FIPS. NULL = all. · default null
Returns columns
legislator_id VARCHAR
Shor-McCarty u_id, stable across a career.
name VARCHAR
Name as recorded, usually 'Last, First'.
party VARCHAR
'D', 'R' or 'X' (independent/other).
state VARCHAR
USPS code, upper case.
np_score DOUBLE
NP-score ideal point in common space.
year INTEGER
Year the legislator served in this chamber.
chamber VARCHAR
'upper', 'lower', or 'legislature' for Nebraska.
district VARCHAR
District that year; numeric districts without leading zeros.
Examples (2)

Texas House party medians by year: how far apart the parties are

SELECT year, party, round(median(np_score), 3) AS median_np
FROM us_statelegs.main.legislator_ideology(state := 'TX')
WHERE chamber = 'lower'
GROUP BY ALL
ORDER BY year, party;

Average ideology of legislators serving since 2020, by state

SELECT state, count(DISTINCT legislator_id) AS legislators,
  round(avg(np_score), 3) AS mean_np
FROM us_statelegs.main.legislator_ideology(first_year := 2020)
GROUP BY state
ORDER BY mean_np;
Link
legislator_roles (state := VARCHAR) 2 examples

Every seat held by current and former state legislators, with dates (keyless, CC0)

Named arguments
state := VARCHAR
Only this state: USPS code such as 'NE' (any case) or two-digit FIPS. NULL = all. · default null
Returns columns
person_id VARCHAR
Open States person id.
name VARCHAR
Full name of the legislator.
state VARCHAR
USPS code of the legislature, upper case.
chamber VARCHAR
'upper', 'lower' or 'legislature'.
district VARCHAR
District name or number, as text.
start_date DATE
Role start date; often NULL for terms recorded before 2018.
end_date DATE
Role end date (scheduled end of term for many sitting members).
end_reason VARCHAR
Why the role ended early, when recorded.
current BOOLEAN
True for a sitting member's role that has not ended.
party VARCHAR
The person's current or last party.
jurisdiction_id VARCHAR
Open States jurisdiction id.
Examples (2)

Ohio legislators who served in both chambers

SELECT person_id, name, count(DISTINCT chamber) AS chambers
FROM us_statelegs.main.legislator_roles(state := 'OH')
GROUP BY ALL
HAVING count(DISTINCT chamber) > 1
ORDER BY name
LIMIT 20;

How many Nebraska seats turned over each year

SELECT year(end_date) AS year, count(*) AS roles_ended
FROM us_statelegs.main.legislator_roles()
WHERE state = 'NE' AND end_date IS NOT NULL
GROUP BY ALL
ORDER BY year;
Link
legislators (current := BOOLEAN, state := VARCHAR) 2 examples

Current and former state legislators from the Open States people data (keyless, CC0)

Named arguments
current := BOOLEAN
true = sitting members only; false = former members only; NULL = both. · default null
state := VARCHAR
Only this state: USPS code such as 'NE' (any case) or two-digit FIPS. NULL = all. · default null
Returns columns
person_id VARCHAR
Open States person id.
name VARCHAR
Full name as Open States records it.
given_name VARCHAR
Given (first) name.
family_name VARCHAR
Family (last) name.
state VARCHAR
USPS code of the legislature, upper case.
current BOOLEAN
True for sitting members.
chamber VARCHAR
Chamber of the most recent legislative role: 'upper', 'lower' or 'legislature'.
district VARCHAR
District of the most recent legislative role, as text.
party VARCHAR
Current (or last recorded) party, e.g. 'Democratic', 'Republican', 'Nonpartisan'.
first_role_start DATE
Earliest recorded legislative role start date.
last_role_end DATE
End of the most recent legislative role.
roles INTEGER
Number of legislative roles.
gender VARCHAR
Gender as recorded by Open States.
birth_date DATE
Date of birth, when recorded with full precision.
death_date DATE
Date of death, when recorded.
email VARCHAR
Official email address.
image VARCHAR
URL of the official photo.
twitter VARCHAR
Official X/Twitter handle.
facebook VARCHAR
Official Facebook account.
instagram VARCHAR
Official Instagram account.
party_history STRUCT(party VARCHAR, start_date DATE, end_date DATE)[]
Every party affiliation recorded, with dates when known.
other_identifiers STRUCT(scheme VARCHAR, identifier VARCHAR)[]
Other ids, e.g. scheme 'legacy_openstates'.
offices STRUCT of 4 fields[]
Capitol and district offices: classification, address, phone, fax.
STRUCT[] 4 fields
  • classificationVARCHAR
  • addressVARCHAR
  • voiceVARCHAR
  • faxVARCHAR
links VARCHAR[]
Official and campaign web pages.
sources VARCHAR[]
Pages the record was compiled from.
Examples (2)

Party balance of the sitting North Carolina General Assembly by chamber

SELECT chamber, party, count(*) AS members
FROM us_statelegs.main.legislators(state := 'NC', current := true)
GROUP BY ALL
ORDER BY chamber, members DESC;

The first ten districts of the unicameral Nebraska Legislature

SELECT name, district, email
FROM us_statelegs.main.legislators(current := true)
WHERE state = 'NE'
ORDER BY district::INTEGER
LIMIT 10;
Link
os_bills (chamber := VARCHAR, classification := VARCHAR, q := VARCHAR, session := VARCHAR, sponsor := VARCHAR, state := VARCHAR, subject := VARCHAR, updated_since := VARCHAR) 2 examples

State bills from the live Open States API with sponsors and actions, newest update first

Named arguments
chamber := VARCHAR
Originating chamber: 'upper', 'lower', 'legislature'. · default null
classification := VARCHAR
Open States bill classification. · default null
q := VARCHAR
Full-text search of bill text and titles. · default null
session := VARCHAR
Session identifier from os_sessions(). · default null
sponsor := VARCHAR
Sponsor name or ocd-person id. · default null
state := VARCHAR
Only this state: USPS code such as 'NE' (any case) or two-digit FIPS. NULL = all. · default null
subject := VARCHAR
Only bills tagged with this subject. · default null
updated_since := VARCHAR
Only bills updated on/after this date, 'YYYY-MM-DD' (or WHERE updated_at >= ...). · default null
Returns columns
bill_id VARCHAR
Open States bill id (ocd-bill/<uuid>).
state VARCHAR
USPS code, upper case.
session VARCHAR
Session identifier.
chamber VARCHAR
Originating chamber: 'upper', 'lower' or 'legislature'.
identifier VARCHAR
Bill number as the state writes it.
title VARCHAR
Bill title.
classification VARCHAR[]
Kinds: 'bill', 'resolution', 'joint resolution', .
subjects VARCHAR[]
Subject terms assigned by the state.
abstract VARCHAR
First abstract/summary, when provided.
first_action_date DATE
Date of the first action.
latest_action_date DATE
Date of the most recent action.
latest_action_description VARCHAR
Text of the most recent action.
latest_passage_date DATE
Date the bill last passed a chamber, if it did.
sponsors STRUCT of 5 fields[]
Sponsorships: name, person_id.
STRUCT[] 5 fields
  • nameVARCHAR
  • person_idVARCHAR
  • entity_typeVARCHAR
  • is_primaryBOOLEAN
  • classificationVARCHAR
actions STRUCT of 4 fields[]
Action history: date, description, chamber, action classifications.
STRUCT[] 4 fields
  • dateDATE
  • descriptionVARCHAR
  • chamberVARCHAR
  • classificationVARCHAR[]
openstates_url VARCHAR
Bill page on Open States.
created_at TIMESTAMP WITH TIME ZONE
When Open States first saw the bill.
updated_at TIMESTAMP WITH TIME ZONE
When Open States last updated the bill.
Examples (2)

Ten recently passed Nebraska bills

SELECT identifier, title, latest_action_date
FROM us_statelegs.main.os_bills(state := 'NE', session := '109')
WHERE latest_passage_date IS NOT NULL
ORDER BY latest_action_date DESC
LIMIT 10;

North Carolina's most prolific primary sponsors among recently updated bills

SELECT s.name, count(*) AS bills
FROM us_statelegs.main.os_bills(state := 'NC', updated_since := '2025-06-01'),
     unnest(sponsors) AS u(s)
WHERE s.is_primary
GROUP BY ALL
ORDER BY bills DESC
LIMIT 10;
Link
os_committees (chamber := VARCHAR, classification := VARCHAR, state := VARCHAR) 1 example

Committees and their rosters for one state from the live Open States API

Named arguments
chamber := VARCHAR
'upper', 'lower' or 'legislature'. · default null
classification := VARCHAR
'committee' or 'subcommittee'. · default null
state := VARCHAR
Only this state: USPS code such as 'NE' (any case) or two-digit FIPS. NULL = all. Required by the API. · default null
Returns columns
committee_id VARCHAR
Open States organization id.
state VARCHAR
USPS code, upper case.
name VARCHAR
Committee name.
classification VARCHAR
'committee' or 'subcommittee'.
parent_id VARCHAR
Parent committee (or chamber) organization id.
members STRUCT of 3 fields[]
Roster: person_name, role, person_id.
STRUCT[] 3 fields
  • person_nameVARCHAR
  • roleVARCHAR
  • person_idVARCHAR
links VARCHAR[]
Committee web pages.
Example

The five largest North Carolina House committees

SELECT name, len(members) AS size
FROM us_statelegs.main.os_committees(state := 'NC', chamber := 'lower')
ORDER BY size DESC
LIMIT 5;
Link
os_events (after_date := VARCHAR, before_date := VARCHAR, state := VARCHAR) 1 example

Committee meetings, hearings and floor sessions for one state from the live Open States API

Named arguments
after_date := VARCHAR
Only events starting after this date 'YYYY-MM-DD'. · default null
before_date := VARCHAR
Only events starting before this date 'YYYY-MM-DD'. · default null
state := VARCHAR
Only this state: USPS code such as 'NE' (any case) or two-digit FIPS. NULL = all. Required by the API. · default null
Returns columns
event_id VARCHAR
Open States event id.
state VARCHAR
USPS code, upper case.
name VARCHAR
Event name (often the committee).
description VARCHAR
Description.
classification VARCHAR
'committee-meeting', 'hearing', 'floor', .
start_time TIMESTAMP WITH TIME ZONE
Start time (UTC).
end_time TIMESTAMP WITH TIME ZONE
End time (UTC), when given.
all_day BOOLEAN
True for all-day events.
status VARCHAR
'tentative', 'confirmed', 'cancelled' or 'passed'.
location_name VARCHAR
Room or venue.
participants STRUCT of 3 fields[]
Participants: name, entity_type, note.
STRUCT[] 3 fields
  • nameVARCHAR
  • entity_typeVARCHAR
  • noteVARCHAR
agenda STRUCT(position BIGINT, description VARCHAR)[]
Agenda items in order.
links VARCHAR[]
Event web pages.
Example

Upcoming North Carolina committee meetings

SELECT start_time, name, location_name
FROM us_statelegs.main.os_events(state := 'NC', after_date := '2026-01-01')
WHERE status <> 'cancelled'
ORDER BY start_time
LIMIT 10;
Link
os_jurisdictions () 1 example

State jurisdictions tracked by the Open States API, with last bill and people update times

No arguments
Returns columns
jurisdiction_id VARCHAR
Open States jurisdiction id.
state VARCHAR
USPS code, upper case.
name VARCHAR
Jurisdiction name.
classification VARCHAR
'state' (DC and PR are also listed as states).
division_id VARCHAR
OCD division id.
url VARCHAR
Official website.
latest_bill_update TIMESTAMP WITH TIME ZONE
When Open States last updated any bill here.
latest_people_update TIMESTAMP WITH TIME ZONE
When Open States last updated any legislator here.
Example

The five states whose bill data were updated least recently

SELECT state, latest_bill_update
FROM us_statelegs.main.os_jurisdictions()
ORDER BY latest_bill_update
LIMIT 5;
Link
os_people (chamber := VARCHAR, district := VARCHAR, name := VARCHAR, state := VARCHAR) 1 example

Current state legislators from the live Open States API (filter by state, name, district)

Named arguments
chamber := VARCHAR
'upper', 'lower' or 'legislature'. · default null
district := VARCHAR
District, e.g. '13' (needs state). · default null
name := VARCHAR
Name search (substring, case-insensitive). · default null
state := VARCHAR
Only this state: USPS code such as 'NE' (any case) or two-digit FIPS. NULL = all. · default null
Returns columns
person_id VARCHAR
Open States person id.
name VARCHAR
Full name.
party VARCHAR
Current party.
state VARCHAR
USPS code, upper case.
chamber VARCHAR
Current chamber: 'upper', 'lower' or 'legislature'.
district VARCHAR
Current district, as text.
role_title VARCHAR
Title of the current role.
division_id VARCHAR
OCD division id of the district.
given_name VARCHAR
Given name.
family_name VARCHAR
Family name.
gender VARCHAR
Gender as recorded.
email VARCHAR
Official email.
image VARCHAR
Photo URL.
birth_date DATE
Date of birth, when known.
openstates_url VARCHAR
Open States profile page.
offices STRUCT of 4 fields[]
Offices: classification, address, phone, fax.
STRUCT[] 4 fields
  • classificationVARCHAR
  • addressVARCHAR
  • voiceVARCHAR
  • faxVARCHAR
links VARCHAR[]
Web pages.
updated_at TIMESTAMP WITH TIME ZONE
When Open States last updated the record.
Example

North Carolina's current state senators by district

SELECT name, party, district
FROM us_statelegs.main.os_people(state := 'NC', chamber := 'upper')
ORDER BY district::INTEGER;
Link
os_sessions (state := VARCHAR) 1 example

Legislative sessions of each state from Open States, with bulk CSV/JSON download links

Named arguments
state := VARCHAR
Only this state: USPS code such as 'NE' (any case) or two-digit FIPS. NULL = all. · default null
Returns columns
state VARCHAR
USPS code, upper case.
jurisdiction_id VARCHAR
Open States jurisdiction id.
session VARCHAR
Session identifier used by os_bills(session := ...), e.g. '2025'.
name VARCHAR
Session name, e.g. '2025-2026 Regular Session'.
classification VARCHAR
'primary' (regular) or 'special'.
start_date DATE
Session start date.
end_date DATE
Session end date.
downloads STRUCT of 3 fields[]
Open States bulk CSV/JSON archives of the session's bills and votes.
STRUCT[] 3 fields
  • data_typeVARCHAR
  • urlVARCHAR
  • updated_atTIMESTAMP WITH TIME ZONE
Example

North Carolina's five most recent sessions

SELECT session, name, start_date
FROM us_statelegs.main.os_sessions(state := 'NC')
ORDER BY start_date DESC
LIMIT 5;
Link
os_votes (chamber := VARCHAR, classification := VARCHAR, q := VARCHAR, session := VARCHAR, sponsor := VARCHAR, state := VARCHAR, subject := VARCHAR, updated_since := VARCHAR) 2 examples

Roll-call votes on state bills from the live Open States API, with individual legislators' votes

Named arguments
chamber := VARCHAR
Originating chamber: 'upper', 'lower', 'legislature'. · default null
classification := VARCHAR
Open States bill classification. · default null
q := VARCHAR
Full-text search of bill text and titles. · default null
session := VARCHAR
Session identifier from os_sessions(). · default null
sponsor := VARCHAR
Sponsor name or ocd-person id. · default null
state := VARCHAR
Only this state: USPS code such as 'NE' (any case) or two-digit FIPS. NULL = all. · default null
subject := VARCHAR
Only bills tagged with this subject. · default null
updated_since := VARCHAR
Only bills updated on/after this date, 'YYYY-MM-DD' (or WHERE updated_at >= ...). · default null
Returns columns
vote_id VARCHAR
Open States vote event id.
bill_id VARCHAR
Bill the vote was on.
bill_identifier VARCHAR
Bill number ('SB 113').
state VARCHAR
USPS code, upper case.
session VARCHAR
Session identifier.
chamber VARCHAR
Chamber that voted: 'upper', 'lower' or 'legislature'.
vote_date DATE
Date of the vote.
motion_text VARCHAR
Motion voted on ('Shall the bill be passed?').
motion_classification VARCHAR[]
Motion kinds, e.g. ['passage'].
result VARCHAR
'pass' or 'fail'.
yes BIGINT
Yes count.
no BIGINT
No count.
other BIGINT
All other counted options.
counts STRUCT(option VARCHAR, value BIGINT)[]
Every reported count by option.
votes STRUCT of 3 fields[]
Individual roll-call votes: option, voter_name, person_id.
STRUCT[] 3 fields
  • optionVARCHAR
  • voter_nameVARCHAR
  • person_idVARCHAR
Examples (2)

Recent final-passage votes in the Nebraska Legislature

SELECT bill_identifier, motion_text, yes, no, result
FROM us_statelegs.main.os_votes(state := 'NE', session := '109')
WHERE 'passage' = ANY(motion_classification)
ORDER BY vote_date DESC
LIMIT 10;

Who cast the most no votes on recently updated North Carolina bills

SELECT v.voter_name, count(*) FILTER (WHERE v.option = 'no') AS no_votes
FROM us_statelegs.main.os_votes(state := 'NC', updated_since := '2025-06-01'),
     unnest(votes) AS u(v)
GROUP BY ALL
ORDER BY no_votes DESC
LIMIT 10;
Link
refresh_cache (dataset VARCHAR) 1 example

Download one dataset again now and report the new cache entry

Arguments
dataset VARCHAR
Dataset to download again now (see cache_info().dataset).
Returns columns
dataset VARCHAR
Dataset key: people, klarner_election_returns, shor_mccarty_*.
description VARCHAR
What the dataset is.
licence VARCHAR
SPDX licence of the upstream data.
source_url VARCHAR
URL the file is (or would be) downloaded from.
source_page VARCHAR
Landing page / DOI of the dataset.
status VARCHAR
'missing', 'cached', or after a refresh 'downloaded'/'not_modified'/'stale'.
cached BOOLEAN
True when a verified copy is in the cache.
path VARCHAR
Path of the cached file.
bytes BIGINT
Size of the cached file.
sha256 VARCHAR
SHA-256 of the cached file.
downloaded_at TIMESTAMP WITH TIME ZONE
When the cached copy was downloaded.
checked_at TIMESTAMP WITH TIME ZONE
When upstream was last checked for a newer copy.
Example

Pull the latest Open States people data now

SELECT dataset, status, bytes
FROM us_statelegs.main.refresh_cache('people');
Link

Credentials

The secret type us_statelegs declares, as reported by the worker itself.

openstates

How to get these credentials

Open States API v3 key (free from Plural) for the os_* bill, vote, people, committee and event functions.

secret.sql
CREATE SECRET openstates (
    TYPE openstates,
    api_key '<OPENSTATES_API_KEY>'  -- secret
);
Key Type Required Description
api_key secret VARCHAR — Open States API v3 key; register free at https://open.pluralpolicy.com/accounts/signup/

The worker doesn't mark which keys are required.

Needed by os_jurisdictionsos_sessionsos_peopleos_billsos_votesos_committeesos_events

Create the secret in the same session, after attaching us_statelegs — the worker registers its secret types at ATTACH. Keys marked secret are masked in duckdb_secrets(); angle-bracket values are placeholders. Read credentials from your environment or secret store in your application and pass them through your SQL client’s parameter bindings. Keep real values out of saved SQL and history. Native DuckDB and Haybarn do not provide a SQL getenv() function.

Try these queries

Party balance of the sitting North Carolina General Assembly by chamber

SELECT chamber, party, count(*) AS members
FROM us_statelegs.main.legislators(state := 'NC', current := true)
GROUP BY ALL
ORDER BY chamber, members DESC

Uses legislators

Ohio legislators who served in both chambers

SELECT person_id, name, count(DISTINCT chamber) AS chambers
FROM us_statelegs.main.legislator_roles(state := 'OH')
GROUP BY ALL
HAVING count(DISTINCT chamber) > 1
ORDER BY name
LIMIT 20

Uses legislator_roles

The largest Nebraska Legislature committees and their chairs

SELECT name, chair, members
FROM us_statelegs.main.committees(state := 'NE')
WHERE classification = 'committee'
ORDER BY members DESC, name
LIMIT 10

Uses committees

Nebraska senators with the most committee assignments

SELECT m.member_name, count(*) AS committees
FROM us_statelegs.main.committee_members(state := 'NE') m
GROUP BY ALL
ORDER BY committees DESC, m.member_name
LIMIT 10

Uses committee_members

How often Wisconsin Assembly incumbents won their general elections, by year

SELECT year,
  round(avg(won::INT) FILTER (WHERE incumbent), 3) AS incumbent_win_rate
FROM us_statelegs.main.election_returns(state := 'WI', chamber := 'lower')
WHERE election_type = 'g'
GROUP BY year
ORDER BY year

Uses election_returns

Texas House party medians by year: how far apart the parties are

SELECT year, party, round(median(np_score), 3) AS median_np
FROM us_statelegs.main.legislator_ideology(state := 'TX')
WHERE chamber = 'lower'
GROUP BY ALL
ORDER BY year, party

Uses legislator_ideology

22 more examples in the Catalog, each listed under the table or function it uses.

Questions it can answer

Plain-English questions from the worker's agent test tasks. An AI agent with this catalog attached should answer each one with SQL.

  • Using the us_statelegs worker, which state-level legislatures are unicameral? Give their USPS codes in alphabetical order.
  • Using the us_statelegs worker, what is the two-digit FIPS code of the state whose jurisdiction id is ocd-jurisdiction/country:us/state:ne/government?
  • Using the us_statelegs worker, how many states call their lower chamber the House of Delegates?
  • Using the us_statelegs worker, how many people currently serve in the Nebraska Legislature according to the Open States people data?
  • Using the us_statelegs worker, how many Ohio legislators in the Open States people data have held seats in both the Ohio House and the Ohio Senate?
  • Using the us_statelegs worker, who chairs the Nebraska Legislature's Agriculture committee, and how many members does that committee have?

US state legislatures is an independent open-source connector from Query.Farm. It is not affiliated with, endorsed by or sponsored by the services, projects or organisations it works with. Product names, logos and trademarks belong to their respective owners.