1 minute read

Introduction

Today, I developed a python program that extracts and tracks US state bills related to artificial intelligence using two different legislative APIs: LegiScan and OpenStates.

Development Notes

I started by downloading relevant librarys for API calls and dataframes.

pip install requests pandas openpyxl

Legiscan

For Legiscan, I created an account and requested an API key to pull the bills.

Using my API key and the base url, I made two methods to first get the states and the session ids since I need them to search the bills.

Screenshot 2025-06-23 at 9 52 10 PM

Then, I use both the states and session ids in my search_ai_bills method since Legiscan’s getBill documentation requries them as params. Additionally, I added “&query=artificial+intelligence” in the URL in order to only search for AI bills.

Screenshot 2025-06-23 at 9 53 46 PM

Have extracted the desired bills, I then get those bills’ details for the excel sheet.

Screenshot 2025-06-23 at 9 54 32 PM

Finally, in my main, I loop through each states and their bills to fetch desired bills and then create a dataframe using pandas to extract them to an excel file

Screenshot 2025-06-23 at 9 55 15 PM

I extraced 943 bills using Legiscan’s API

OpenStates

For OpenStates, I pretty much used the same framework to extract the bills.

First of all, I created an account to request an API key

Then I use the /jurisdiction root in my get_jurisdiction method to only find all states by adding a “state” classification to my url = f”{BASE_URL}/jurisdictions?classification=state”

Screenshot 2025-06-23 at 9 58 25 PM

With those jurisdictions, I used the /bills root with certian params to search for AI bills. Then, I loop through every AI bill I have and append more information about them for the excel file.

Screenshot 2025-06-23 at 9 59 55 PM

Lastly, I call on both methods in my main to extract the AI bills into an excel file using pandas

Screenshot 2025-06-23 at 10 02 44 PM

Issue: The abstract query isn’t working in my search_ai_bills method

OpenStates request limit: Due to this limit, I can only extract a few hundred bills at once