Legacy API
The legacy API provides 100% backwards compatibility with the original uszipcode library. This ensures that existing code can migrate to ZipSearch without any modifications.
Overview
The SearchEngine class maintains the exact same interface as the original uszipcode.SearchEngine, but with dramatically improved performance through pre-built RAM indices.
Migration
Simply change your import statement:
Query Method
The query method provides the most flexible search interface, supporting multiple search patterns and filters in a single call.
Backwards compatible query method for searching zipcode data.
This method provides compatibility with the original zipsearch API while leveraging the new fast search infrastructure. It supports multiple search patterns and filters to find zipcodes based on various criteria.
Args: zipcode (str, optional): Exact zipcode to lookup (e.g., "90210") prefix (str, optional): Zipcode prefix to search (e.g., "902" finds all 902xx codes) pattern (str, optional): Pattern to search within zipcode strings city (str, optional): City name to search for state (str, optional): State abbreviation (e.g., "CA", "NY") lat (float, optional): Latitude for coordinate-based search lng (float, optional): Longitude for coordinate-based search radius (float, optional): Search radius in miles (requires lat/lng) zipcode_type (ZipcodeTypeEnum, optional): Filter by zipcode type (STANDARD, PO_BOX, etc.) sort_by (str, optional): Sort criteria (e.g., SORT_BY_DIST for distance) ascending (bool, optional): Sort order direction. Defaults to True. returns (int, optional): Maximum number of results to return **kwargs: Additional demographic filters including: - population_lower (int): Minimum population threshold - population_upper (int): Maximum population threshold - median_household_income_lower (int): Minimum income threshold - median_household_income_upper (int): Maximum income threshold - median_home_value_lower (int): Minimum home value threshold - median_home_value_upper (int): Maximum home value threshold
Returns: list[FastZipcode]: List of matching zipcode objects. Returns empty list if no matches.
Examples: >>> engine = SearchEngine() >>> # Single zipcode lookup >>> results = engine.query(zipcode="90210") >>> >>> # Find all zipcodes starting with 902 >>> results = engine.query(prefix="902") >>> >>> # Search by city and state >>> results = engine.query(city="Beverly Hills", state="CA") >>> >>> # Coordinate search within 10 miles >>> results = engine.query(lat=34.0901, lng=-118.4065, radius=10) >>> >>> # Demographic filtering >>> results = engine.query(state="CA", population_lower=50000, returns=10)
Note: This method maintains 100% backwards compatibility with the original API. Complex demographic queries are simplified but functional. For optimal performance, prefer the new direct methods like by_zipcode(), by_city(), etc.
Source code in zipsearch/boilerplate.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | |
Performance Notes
While the legacy API maintains full compatibility, consider using the new FastSearchEngine class for optimal performance:
- Direct method calls (
by_zipcode,by_city_and_state) are faster than the genericquerymethod - Batch operations are available for ETL workflows
- Simplified parameter handling reduces overhead
Examples
Basic Searches
Advanced Filtering
Compatibility Notes
- Complex demographic queries are simplified but functional
- All original parameter names and types are supported
- Return objects maintain identical structure and properties
- Error handling behavior matches original implementation