Skip to content
A Python library that standardizes the names of U.S. states
Find file
New pull request
Latest commit f656bcb @palewire palewire Upped to version 0.1.6
Failed to load latest commit information.
statestyle iteritems fix for Python 3
.coveragerc Attempted integration for #5.
.gitignore New setup style
.travis.yml YAML fix Typo Added 'Washington, DC' for #7
requirements.txt Simplify requirements file Upped to version 0.1.6 dict object conversion, docs and other fine points for #8
tox.ini iteritems fix for Python 3

8""""8                           8""""8
8      eeeee eeeee eeeee eeee    8      eeeee e    e e     eeee
8eeeee   8   8   8   8   8       8eeeee   8   8    8 8     8
    88   8e  8eee8   8e  8eee        88   8e  8eeee8 8e    8eee
e   88   88  88  8   88  88      e   88   88    88   88    88
8eee88   88  88  8   88  88ee    8eee88   88    88   88eee 88ee 

A Python library that standardizes the names of U.S. states

Build Status PyPI version Coverage Status


  • Submit a state’s name, postal code or Associated Press abbreviation or FIPS code and receive a clean object with all other formats as attributes.
  • State objects also provide the “stateface” code for ProPublica’s web font of state shapes

Getting started

Getting started is as easy as…

$ pip install latimes-statestyle

Then start feeding it your data.

>>> import statestyle
# Get by postal code
>>> obj = statestyle.get('CA')

If there is a match you can access the clean, standardized attributes.

# Here's the full name of the state
>>> print
# The U.S. postal code
>>> print obj.postal
# The Associated Press style abbreviation
>>> print obj.ap
# The FIPS ID code
>>> print obj.fips
# The type of geographic area
>>> print obj.type
# The ProPublica stateface code
>>> obj.stateface

You can pass in any of the attributes for a match.

# Like the FIPS code
>>> obj = statestyle.get(6)
# And the same attributes available
>>> print

Here's what happens when you submit something that doesn't have a match.

>>> statestyle.get("foo")
Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "statestyle/", line 27, in get
    raise ValueError("The state you requested does not exist")
ValueError: The state you requested does not exist

And here's a couple ways you can convert the object it returns to a dictionary.

>>> o = statestyle.get("CA")
>>> dict(o)
{'name': 'California', 'ap': 'Calif.', 'fips': '6', 'postal': 'CA', 'type': 'state', 'stateface': 'E'}
>>> o.to_dict()
{'name': 'California', 'ap': 'Calif.', 'fips': '6', 'postal': 'CA', 'type': 'state', 'stateface': 'E'}
# You can also access the attributes as dictionary keys if you want
>>> o['name']


If you would like to add another feature or change existing data, edit statestyle/data.csv and then run python, which will remake the data file imported by the library.

Something went wrong with that request. Please try again.