Welcome to wa-leg-api’s documentation!

wa-leg-api provides a python library interface to the Washington State Legislature.

Quick Start

Installation

git clone https://github.com/j-carson/wa-leg-api.git
cd wa-leg-api
pip install . 

Dependecies are:

Usage

The stub functions are in modules named after each service in all lower case. The function names are the request type changed from CamelCase to snake_case.

Example: If you want to call the function GetAmendments from the AmendmentService, do:

from wa_leg_api.amendment import get_amendments
result = get_amendments(2021)

All stubs return dicts.

For more information about the Washington State Legislature web services available visit wslwebservices.leg.wa.gov

Exceptions

There is one exception defined by this library:

try:
    result = get_amendments(2100)  # an invalid year!
except WaLegApiException as e:
    print(e.http_error)      # HTTP Error code
    print(e.http_error_text) # HTTP Error code as text
    print(e.http_text)       # Additional text returned from leg.wa.gov 
    print(e.args_sent)       # Record of arguments sent with request

Sample output:

500
Internal Server Error
System.Web.Services.Protocols.SoapException: Invalid Input. ---> System.ArgumentException: You have not submitted a valid year.  Please enter year in the following format:  YYYY.  Information is only available back to 1991.
Parameter name: Year
   --- End of inner exception stack trace ---
   at WslWebServices.AmendmentService.GetAmendments(Int32 year)

{'year': 2100}

Exceptions thrown directly by the requests package are not re-wrapped.

To dos

The stub functions accept arguments of the correct type, but applying type information for the return values is not yet implemented, so every field is returned as a string.

The input arg names are in python-standard camelcase, but the return keys in the dictionary are not yet camel-cased. They are all lower case.

The documentation should really include the dict structure returned, rather than pointing to the leg.wa.gov documentation.

Developers

The source is here.

In addition to the required packages to use the library, the lxml package is needed to regenerate the stubs. The function that makes the stubs is called make_stubs.py

The tests are compatible with pytest. The documentation is built with sphinx.

User-level API’s

The user-level API consists of thin python stubs for each interface provided by the Washington legislature’s web services.

  • The module name is the XML service name, converted to lower case, without the word “Service” on the end. The module name is not converted to snake_case, so CommitteeMeetingService is in the committeemeeting module

  • The function in the service is the XML API name, converted from camel case to snake case, so GetAmendments becomes get_amendments.

  • The argment names are also converted to camel_case within each wrapper function

Note

The details of using each API are not documented here. See the link to the page on the legistature website with technical details and a test form.

Warning

This is alpha code. The returned dictionaries are subject to change in future versions. In particular, I hope to cast returned values to their proper types and change the variable names to camel_case like the stub functions use.

AmendmentService

CommitteeService

CommitteeMeetingService

LegislationService

LegislativeDocumentService

RCWCiteAffectedService

SessionLawService

SponsorService

Exception

If the leg.wa.gov server returns status other than 200, the exception raised is WaLegApiException:

exception WaLegApiException(http_error_num: int, http_error_text: str, http_text: str, args_sent: Dict)[source]

Throws an exception with useful info for debugging

Low-level Functions

The functions below are likely only of interest if you want to develop new features for this library.

make_stubs

This module auto-generates source code for the user-level API’s

waleg

This module is the backend for the stub functions

Indices and tables