API Docs¶
Raw Data API Python Client¶
Client¶
Get OSM data for a specified area.
This is a convenience wrapper around RawDataClient.get_osm_data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
geometry
|
dict[str, Any] | str
|
GeoJSON geometry object or string |
required |
output_options
|
RawDataOutputOptions
|
Options for controlling output behavior |
default()
|
**kwargs
|
Additional parameters for customizing the request - fileName: Name for the export file (default: "osm_export") - outputType: Format of the output (default: "geojson") - bindZip: Whether to retrieve results as a zip file (default: False) - filters: Dictionary of filters to apply - geometryType: List of geometry types to include |
{}
|
Returns:
Type | Description |
---|---|
RawDataResult
|
Object containing metadata, plus a filepath or data. |
Raises:
Type | Description |
---|---|
ValidationError
|
If inputs are invalid |
APIRequestError
|
If the API request fails |
TaskPollingError
|
If polling the task status fails |
DownloadError
|
If downloading data fails |
Source code in osm_data_client/client.py
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 |
|
options: show_source: false heading_level: 3
Client for fetching OSM data via the HOTOSM Raw Data API.
This client provides a high-level interface for requesting and downloading OpenStreetMap data for a specified area with customizable filters.
Source code in osm_data_client/client.py
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 |
|
__init__(config=RawDataClientConfig.default())
¶
Initialize the client.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
RawDataClientConfig
|
Configuration for the client |
default()
|
Source code in osm_data_client/client.py
292 293 294 295 296 297 298 299 300 |
|
get_osm_data(geometry, output_options=RawDataOutputOptions.default(), **kwargs)
async
¶
Get OSM data for a specified area.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
geometry
|
dict[str, Any] | str
|
GeoJSON geometry object or string |
required |
output_options
|
RawDataOutputOptions
|
Options for controlling output behavior |
default()
|
**kwargs
|
Additional parameters for customizing the request - fileName: Name for the export file (default: "osm_export") - outputType: Format of the output (default: "geojson") - bindZip: Whether to retrieve results as a zip file (default: False) - filters: Dictionary of filters to apply - geometryType: List of geometry types to include |
{}
|
Returns:
Type | Description |
---|---|
RawDataResult | dict
|
Object containing metadata, plus a filepath or data. |
Raises:
Type | Description |
---|---|
ValidationError
|
If inputs are invalid |
APIRequestError
|
If the API request fails |
TaskPollingError
|
If polling the task status fails |
DownloadError
|
If downloading data fails |
Examples:
>>> data_path = await get_osm_data(
... {"type": "Polygon", "coordinates": [...]},
... fileName="my_buildings",
... outputType="geojson",
... filters={"tags": {"all_geometry": {"building": []}}}
... )
Source code in osm_data_client/client.py
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 |
|
options: show_source: false heading_level: 3
Client for the HOTOSM Raw Data API.
Source code in osm_data_client/client.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 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 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 |
|
__init__(config=RawDataClientConfig.default())
¶
Initialize the API client.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
RawDataClientConfig
|
Configuration for the client |
default()
|
Source code in osm_data_client/client.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
|
download_to_disk(data, options=RawDataOutputOptions.default())
async
¶
Stream data from API to disk
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
RawDataApiMetadata
|
Metadata containing download information |
required |
options
|
RawDataOutputOptions
|
Options for controlling extraction behavior |
default()
|
Returns:
Type | Description |
---|---|
RawDataResult
|
RawDataResult with information about the downloaded file |
Raises:
Type | Description |
---|---|
DownloadError
|
If downloading or processing fails |
Source code in osm_data_client/client.py
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 |
|
poll_task_status(task_link, polling_interval=2)
async
¶
Poll the API to check task status until completion.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
task_link
|
str
|
Task tracking URL |
required |
polling_interval
|
int
|
Seconds between polling attempts |
2
|
Returns:
Type | Description |
---|---|
dict[str, Any]
|
Task status details |
Raises:
Type | Description |
---|---|
TaskPollingError
|
If polling fails |
Source code in osm_data_client/client.py
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 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
|
request_plain_geojson_snapshot(geometry, params)
async
¶
Request a snapshot of OSM geojson data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
geometry
|
GeometryInput
|
Validated GeoJSON geometry object |
required |
params
|
RequestParams
|
Validated request parameters |
required |
Returns:
Type | Description |
---|---|
dict[str, Any]
|
Plain geojson of osm features |
Raises:
Type | Description |
---|---|
APIRequestError
|
If the API request fails |
Source code in osm_data_client/client.py
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 |
|
request_snapshot(geometry, params)
async
¶
Request a snapshot of OSM data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
geometry
|
GeometryInput
|
Validated GeoJSON geometry object |
required |
params
|
RequestParams
|
Validated request parameters |
required |
Returns:
Type | Description |
---|---|
dict[str, Any]
|
API response with task tracking information |
Raises:
Type | Description |
---|---|
APIRequestError
|
If the API request fails |
Source code in osm_data_client/client.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 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 |
|
options: show_source: false heading_level: 3
Results¶
Result object containing processed file path and associated metadata.
Attributes:
Name | Type | Description |
---|---|---|
path |
Optional[Path]
|
Path to the final processed file or directory |
data |
Optional[dict]
|
dict representation of data |
metadata |
RawDataApiMetadata
|
Original metadata from the API response |
extracted |
bool
|
Whether the file was extracted from an archive |
original_path |
Optional[Path]
|
Path to the original downloaded file (if different from path) |
extracted_files |
Optional[list[Path]]
|
List of files that were extracted (if applicable) |
Source code in osm_data_client/processing.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
|
__str__()
¶
Return string representation of the result.
Source code in osm_data_client/processing.py
47 48 49 50 51 |
|
exists()
¶
Check if the result file or directory exists.
Source code in osm_data_client/processing.py
35 36 37 38 39 |
|
suffix()
¶
Get file type suffix, if path exists.
Source code in osm_data_client/processing.py
41 42 43 44 45 |
|
options: show_source: false heading_level: 3
Models¶
Validated geometry input for OSM API requests.
Source code in osm_data_client/models.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 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 |
|
from_input(geometry)
classmethod
¶
Create a GeometryInput from either a dictionary or a JSON string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
geometry
|
dict[str, Any] | str
|
GeoJSON geometry object or string |
required |
Returns:
Type | Description |
---|---|
GeometryInput
|
Validated GeometryInput object |
Raises:
Type | Description |
---|---|
ValidationError
|
If geometry is invalid |
Source code in osm_data_client/models.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 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 |
|
to_dict()
¶
Convert to dictionary representation.
Source code in osm_data_client/models.py
124 125 126 |
|
options: show_source: false heading_level: 3
Validated parameters for OSM API requests.
Source code in osm_data_client/models.py
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 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
|
from_kwargs(**kwargs)
classmethod
¶
Create a RequestParams from keyword arguments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs
|
Keyword arguments for request parameters |
{}
|
Returns:
Type | Description |
---|---|
RequestParams
|
Validated RequestParams object |
Raises:
Type | Description |
---|---|
ValidationError
|
If parameters are invalid |
Source code in osm_data_client/models.py
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 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
|
to_api_params()
¶
Convert to API parameter dictionary.
Source code in osm_data_client/models.py
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
|
validate_bind_zip_compatibility(output_type, bind_zip)
staticmethod
¶
Validate if the output format is compatible with bindZip=False
Source code in osm_data_client/models.py
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
|
options: show_source: false heading_level: 3
Immutable metadata about a dataset
Source code in osm_data_client/models.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 |
|
__str__()
¶
Returns a string representation of RawDataApiMetadata for debugging purposes.
Source code in osm_data_client/models.py
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 |
|
from_api_result(result, params)
classmethod
¶
Create a RawDataApiMetadata from API result and request parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
result
|
dict[str, Any]
|
API result dictionary from task status |
required |
params
|
RequestParams
|
Request parameters used for the API request |
required |
Returns:
Type | Description |
---|---|
RawDataApiMetadata
|
RawDataApiMetadata instance |
Source code in osm_data_client/models.py
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 |
|
options: show_source: false heading_level: 3
Bases: Enum
Options for controlling extraction behavior of ZIP archives.
Source code in osm_data_client/models.py
312 313 314 315 316 317 |
|
options: show_source: false heading_level: 3
Configuration for Raw Data API client.
Source code in osm_data_client/models.py
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 |
|
options: show_source: false heading_level: 3
Options for controlling how output data is handled.
Source code in osm_data_client/models.py
340 341 342 343 344 345 346 347 348 349 350 |
|
default()
classmethod
¶
Create default output options.
Source code in osm_data_client/models.py
347 348 349 350 |
|
options: show_source: false heading_level: 3