Skip to main content
<pre><code>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 </code></pre>

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

[![Build Status](https://travis-ci.org/datadesk/latimes-statestyle.png?branch=master)](https://travis-ci.org/datadesk/latimes-statestyle)
[![PyPI version](https://badge.fury.io/py/latimes-statestyle.png)](http://badge.fury.io/py/latimes-statestyle)
[![Coverage Status](https://coveralls.io/repos/datadesk/latimes-statestyle/badge.png?branch=master)](https://coveralls.io/r/datadesk/latimes-statestyle?branch=master)

* Issues: [https://github.com/datadesk/latimes-statestyle/issues](https://github.com/datadesk/latimes-statestyle/issues)
* Packaging: [https://pypi.python.org/pypi/latimes-statestyle](https://pypi.python.org/pypi/latimes-statestyle)
* Testing: [https://travis-ci.org/datadesk/latimes-statestyle](https://travis-ci.org/datadesk/latimes-statestyle)
* Coverage: [https://coveralls.io/r/datadesk/latimes-statestyle](https://coveralls.io/r/datadesk/latimes-statestyle)

Features
--------

- Submit a state’s name, postal code or Associated Press abbreviation or [FIPS
code](https://en.wikipedia.org/wiki/Federal_Information_Processing_Standards)
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](http://propublica.github.com/stateface/)

Getting started
---------------

Getting started is as easy as…

```bash
$ pip install latimes-statestyle
```

Then start feeding it your data.

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

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

```python
# Here's the full name of the state
>>> print obj.name
California
# The U.S. postal code
>>> print obj.postal
CA
# The Associated Press style abbreviation
>>> print obj.ap
Calif.
# The FIPS ID code
>>> print obj.fips
6
# The type of geographic area
>>> print obj.type
state
# The ProPublica stateface code
>>> obj.stateface
"E"
```

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

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

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

```python
>>> statestyle.get("foo")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "statestyle/__init__.py", 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.

```python
>>> 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']
'California'
```

Contributing
------------

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

Metadata

Release files for latimes-statestyle 0.1.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for latimes-statestyle 0.1.6
File Size Uploaded Provenance Actions
latimes-statestyle-0.1.6.tar.gz 8.9 kB Without provenance Details for latimes-statestyle-0.1.6.tar.gz

Release files / latimes-statestyle-0.1.6.tar.gz

Download URL latimes-statestyle-0.1.6.tar.gz
Size 8.9 kB
Tags Source
SHA-256 checksum
How to use checksums
7f3a6fed8a226458fd2be284ac4a28c5ed06159d6544ac5d0cfe34830a3d4905
BLAKE2b-256 checksum
How to use checksums
5f8adfd64823f0b4bcad4f052ea90a42b6e48b113a75781b2d52751c4d75d6ad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for latimes-statestyle 0.1.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page