A lightweight Python package for extracting data from Esri REST API endpoints.
- Multiple export formats: Export to GeoJSON, Shapefile, CSV, File Geodatabase, and GeoDataFrame.
- Robust extraction: Automatically handles Esri's pagination.
- Filtering: Filter data by bounding box or attribute query.
- Bulk exports: Download all layers from a MapServer or FeatureServer.
- Simple CLI: An easy-to-use command-line interface for all features.
- Human-readable metadata: Get a clean summary of layer metadata.
pip install ezesri
You can use ezesri
as a library to integrate with your Python scripts.
import ezesri
# URL for a public Esri feature layer, e.g. City of Los Angeles boundaries:
# https://services5.arcgis.com/VAb1qw880ksyBtIL/ArcGIS/rest/services/City_Boundary_of_Los_Angeles_(new)/FeatureServer/0
url = "your_esri_layer_url_here"
# Get layer metadata
metadata = ezesri.get_metadata(url)
print(ezesri.summarize_metadata(metadata))
# Extract layer to a GeoDataFrame
gdf = ezesri.extract_layer(url)
print(gdf.head())
ezesri
also provides a command-line tool for quick data extraction.
Get a clean, human-readable summary of a layer's metadata.
ezesri metadata <YOUR_ESRI_LAYER_URL>
To get the raw JSON output, use the --json
flag:
ezesri metadata <YOUR_ESRI_LAYER_URL> --json
You can fetch a layer and save it to a file in various formats.
-
GeoJSON
ezesri fetch <YOUR_ESRI_LAYER_URL> --format geojson --out output.geojson
-
Shapefile
ezesri fetch <YOUR_ESRI_LAYER_URL> --format shapefile --out output.shp
-
CSV (geometry is dropped)
ezesri fetch <YOUR_ESRI_LAYER_URL> --format csv --out output.csv
-
File Geodatabase
ezesri fetch <YOUR_ESRI_LAYER_URL> --format gdb --out output.gdb
You can also filter by a bounding box (in WGS84 coordinates):
ezesri fetch <URL> --bbox <xmin,ymin,xmax,ymax> --format geojson --out <FILE>
Or, use a more advanced spatial filter with a GeoJSON object:
ezesri fetch <URL> --geometry '{"type": "Polygon", ...}' --format geojson --out <FILE>
You can discover and export all layers from a MapServer or FeatureServer to a specified directory.
ezesri bulk-fetch <YOUR_ESRI_SERVICE_URL> <YOUR_OUTPUT_DIRECTORY> --format gdb
To make the CLI easier to use, the following aliases are available for common options:
--out
:--output
--format
:--fmt
--spatial-rel
:--srs
For a detailed, real-world example of using ezesri
to acquire, process, and visualize data, see the scripts in the examples/
directory:
examples/palm_springs_fetch.py
: Demonstrates how to useezesri
to download data from multiple Esri feature layers, merge them based on a common attribute, and save the result as a GeoJSON file.examples/palm_springs_pools_map.py
: Shows how to load the prepared data, perform analysis to identify residential properties, and create a final map visualizing the results withmatplotlib
.
To run these examples, you will first need to install the required dependencies:
pip install geopandas matplotlib
Then, you can run the scripts directly:
python examples/palm_springs_fetch.py
python examples/palm_springs_pools_map.py
This project uses pytest
for unit testing. For details on how to run the test suite, please see the testing guide.
Contributions are welcome! Please feel free to submit a pull request or open an issue to discuss your ideas.