City of Boston Python utilities for ArcGIS and data management
Project description
cityofboston
City of Boston Python utilities for working with ArcGIS Feature Servers and Boston-specific data systems.
Features
Generic ArcGIS Client (cityofboston.arcgis)
- Work with any ArcGIS Feature Server
- Flexible authentication (username/password, token, or anonymous)
- Pagination support for large datasets
- Export to CSV
- Update features
SAM Client (cityofboston.sam)
- Convenience wrapper for Boston's Street Address Management (SAM) system
- Pre-configured layer definitions for TEST and PROD environments
- Easy access to addresses, buildings, street segments, and more
Installation
pip install cityofboston
Optional dependencies
For geospatial export formats (GeoJSON, Shapefile, GeoPackage):
pip install cityofboston[geo]
For development:
pip install cityofboston[dev]
Usage
Generic ArcGIS Client
Work with any ArcGIS Feature Server:
from cityofboston.arcgis import ArcGISClient, UsernamePasswordAuth
# Authenticated access
auth = UsernamePasswordAuth(
portal_url="https://portal.example.com",
username="myuser",
password="mypass"
)
client = ArcGISClient(auth=auth)
# Query features
layer_url = "https://services.arcgis.com/ORG/arcgis/rest/services/MyService/FeatureServer/0"
for feature in client.query_features(layer_url, where="STATE='MA'"):
print(feature)
# Get feature count
count = client.get_feature_count(layer_url, where="STATE='MA'")
print(f"Found {count} features")
# Export to CSV
client.export_to_csv(layer_url, "output.csv", where="STATE='MA'")
SAM Client
Easy access to Boston's Street Address Management data:
from cityofboston.sam import SAMClient, SAMLayer, SAMEnvironment
# Connect to TEST environment (reads credentials from env vars)
client = SAMClient(environment=SAMEnvironment.TEST)
# Or pass credentials directly
client = SAMClient(
environment=SAMEnvironment.PROD,
username="myuser",
password="mypass"
)
# Query addresses in a specific ZIP code
for address in client.query_layer(
SAMLayer.ADDRESSES,
where="ZIP_CODE='02127'"
):
print(address)
# Get feature count
count = client.get_feature_count(SAMLayer.ADDRESSES)
print(f"Total addresses: {count}")
# Export to CSV
client.export_to_csv(
SAMLayer.ADDRESSES,
"addresses.csv",
where="ZIP_CODE='02127'"
)
# Update features
updates = [
{"attributes": {"OBJECTID": 123, "ZIP_CODE": "02127"}},
{"attributes": {"OBJECTID": 456, "ZIP_CODE": "02115"}}
]
result = client.update_features(SAMLayer.ADDRESSES, updates)
# Lookup street name by segment ID
street_name = client.get_street_name_by_segment_id(12345)
Available SAM Layers
SAMLayer.ADDRESSES- Address pointsSAMLayer.BUILDINGS- Building polygonsSAMLayer.STREET_SEGMENTS- Street centerlinesSAMLayer.MASTER_STREET_NAMES- Master street name tableSAMLayer.STREET_ALIASES- Street name aliasesSAMLayer.BOSTON_ZIP_CODES- ZIP code boundaries
Authentication
Environment Variables
The SAM client reads credentials from environment variables by default:
For TEST environment:
TEST_ARCGIS_USERNAMETEST_ARCGIS_PASSWORD
For PROD environment:
PROD_ARCGIS_USERNAMEPROD_ARCGIS_PASSWORD
Create a .env file:
TEST_ARCGIS_USERNAME=myuser
TEST_ARCGIS_PASSWORD=mypass
Direct Credentials
You can also pass credentials directly:
from cityofboston.sam import SAMClient, SAMEnvironment
client = SAMClient(
environment=SAMEnvironment.PROD,
username="myuser",
password="mypass"
)
Public/Anonymous Access
For public layers that don't require authentication:
from cityofboston.arcgis import ArcGISClient
client = ArcGISClient() # No auth needed
Development
This project uses uv for dependency management and building.
# Clone the repository
git clone https://github.com/CityOfBoston/cityofboston-python.git
cd cityofboston-python
# Install uv if you haven't already
curl -LsSf https://astral.sh/uv/install.sh | sh
# Create a virtual environment and install dependencies
uv venv
uv pip install -e ".[dev]"
# Run tests
uv run pytest
Publishing to PyPI
This package is published to PyPI under the cityofboston organization. Publishing is automated via GitHub Actions when a new release is created.
Manual Publishing
If you need to publish manually:
# Build the package using uv
uv build
# Upload to PyPI (requires PyPI credentials)
uv publish
Contributing
Issues and pull requests welcome at https://github.com/CityOfBoston/cityofboston-python
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cityofboston-0.1.0.tar.gz.
File metadata
- Download URL: cityofboston-0.1.0.tar.gz
- Upload date:
- Size: 8.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
44d25e656a8800fd447a1a43716ff15cce982035fe79df2beb0bf2aefd6f3f47
|
|
| MD5 |
e503d78b48c7ab12cb451652d4413d05
|
|
| BLAKE2b-256 |
7347f793fca95b2d88b87c5cd41a86b6ccb65acded4e41cd51aa24ead9faa440
|
Provenance
The following attestation bundles were made for cityofboston-0.1.0.tar.gz:
Publisher:
publish.yml on CityOfBoston/cityofboston-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cityofboston-0.1.0.tar.gz -
Subject digest:
44d25e656a8800fd447a1a43716ff15cce982035fe79df2beb0bf2aefd6f3f47 - Sigstore transparency entry: 688680485
- Sigstore integration time:
-
Permalink:
CityOfBoston/cityofboston-python@f37a9edf9d22c095a7002ccf3cf970d91e7f334a -
Branch / Tag:
refs/heads/main - Owner: https://github.com/CityOfBoston
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f37a9edf9d22c095a7002ccf3cf970d91e7f334a -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file cityofboston-0.1.0-py3-none-any.whl.
File metadata
- Download URL: cityofboston-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
025c674d6c813aa9c5d515e4db268c76463e37160163f4837d7a708ac2867b01
|
|
| MD5 |
5d3c6c6a799a00f4864535947ee29cc9
|
|
| BLAKE2b-256 |
ef73e3516f1da5573948865bb2f4512b79f61248113891b162f94738f408f77a
|
Provenance
The following attestation bundles were made for cityofboston-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on CityOfBoston/cityofboston-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cityofboston-0.1.0-py3-none-any.whl -
Subject digest:
025c674d6c813aa9c5d515e4db268c76463e37160163f4837d7a708ac2867b01 - Sigstore transparency entry: 688680503
- Sigstore integration time:
-
Permalink:
CityOfBoston/cityofboston-python@f37a9edf9d22c095a7002ccf3cf970d91e7f334a -
Branch / Tag:
refs/heads/main - Owner: https://github.com/CityOfBoston
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f37a9edf9d22c095a7002ccf3cf970d91e7f334a -
Trigger Event:
workflow_dispatch
-
Statement type: