A read-only interface to OpenStreetMap change APIs and files
Project description
osmdiff
A read-only interface to OpenStreetMap change APIs and files. See also pyosm which can do similar things.
Documentation
📚 Comprehensive documentation is available at mvexel.github.io/osmdiff
Python Version Support
This module has been tested with Python 3.8 - 3.12. Use at your own risk with other versions.
Installing
pip install osmdiff
Usage
See the documentation for more details.
Reading
Retrieve the latest replication diff from the OSM API:
>>> from osmdiff import OSMChange
>>> o = OSMChange(frequency="minute") # minute is the default frequency
>>> o.get_state() # retrieve current sequence ID
>>> o.sequence_number
2704451
>>> o.retrieve() # retrieve from API
>>> o
OSMChange (677 created, 204 modified, 14 deleted)
Read a replication diff from a file:
>>> from osmdiff import OSMChange
>>> o = OSMChange(file="test_osmchange.xml")
>>> o
OSMChange (831 created, 368 modified, 3552 deleted)
Retrieve the latest Augmented Diff from Overpass:
>>> from osmdiff import AugmentedDiff
>>> a = AugmentedDiff()
>>> a.get_state()
>>> a.sequence_number
2715051
>>> a.retrieve()
>>> a
AugmentedDiff (747 created, 374 modified, 55 deleted)
Read an augmented diff file:
>>> from osmdiff import AugmentedDiff
>>> a = AugmentedDiff(file="test_adiff.xml")
>>> a
AugmentedDiff (2329 created, 677 modified, 39 deleted)
Inspect contents
Get all the things that chris66 has created:
>>> [n for n in a.create if n.attribs["user"] == "chris66"]
[Node 5221564287, Node 5221564288, Node 5221564289, Node 5221564290, Node 5221564291, Node 5221564292, Node 5221564293, Node 5221564294, Node 5221564295, Node 5221564296, Node 5221564297, Node 5221564298, Node 5221564299, Node 5221564301, Node 5221564302, Node 5221564303, Node 5221564304, Way 539648222 (5 nodes), Way 539648223 (5 nodes), Way 539648323 (5 nodes)]
Get all residential ways that were modified:
>>> [n["new"] for n in a.modify if type(n["new"]) == Way and n["new"].tags.get("highway") == "residential"]
[Way 34561958 (3 nodes), Way 53744484 (6 nodes), Way 53744485 (6 nodes), Way 122650942 (3 nodes), Way 283221266 (4 nodes), Way 344272652 (5 nodes), Way 358243999 (13 nodes), Way 410489319 (5 nodes), Way 452218081 (10 nodes)]
Get all ways that were changed to residential from something else:
>>> [n["new"] for n in a.modify if type(n["new"]) == Way and n["new"].tags.get("highway") == "residential" and n["old"].tags["highway"] != "residential"]
[Way 410489319 (5 nodes), Way 452218081 (10 nodes)]
Inspect details:
>>> w = [n["new"] for n in a.modify if n["new"].attribs["id"] == "452218081"]
>>> w
[Way 452218081 (10 nodes)]
>>> w[0]
Way 452218081 (10 nodes)
>>> w[0].tags
{'highway': 'residential'}
>>> w[0].attribs
{'id': '452218081', 'version': '2', 'timestamp': '2017-11-10T13:52:01Z', 'changeset': '53667190', 'uid': '2352517', 'user': 'carths81'}
>>> w[0].attribs
{'id': '452218081', 'version': '2', 'timestamp': '2017-11-10T13:52:01Z', 'changeset': '53667190', 'uid': '2352517', 'user': 'carths81'}
>>> w[0].bounds
['12.8932677', '43.3575917', '12.8948117', '43.3585947']
Iterating
To continuously iterate over AugmentedDiff objects, use ContinuousAugmentedDiff:
>>> for a in ContinuousAugmentedDiff():
... print(a)
This will iterate indefinitely, printing each AugmentedDiff as it is retrieved.
You can also use it in a loop:
for a in ContinuousAugmentedDiff():
if a.sequence_number > 123456:
break
print(a)
Configuration
The osmdiff package uses a centralized configuration system in src/osmdiff/config.py. This includes:
API Configuration
Default settings for API endpoints and timeouts:
API_CONFIG = {
"overpass": {"base_url": "...", "timeout": 30},
"osm": {"base_url": "...", "timeout": 30},
"nominatim": {"base_url": "...", "timeout": 30}
}
Request Headers
Standard headers used in all API requests:
DEFAULT_HEADERS = {
"User-Agent": "osmdiff/1.0",
"Accept": "application/json, text/xml"
}
Customizing Configuration
You can override any configuration value at runtime by passing parameters to the respective class constructors:
from osmdiff import OSMChange
# Override default URL and timeout
change = OSMChange(
url="https://custom-api.example.com",
timeout=60
)
Community
Join the conversation and get help:
- GitHub Discussions - For questions, ideas, and general discussion
- OpenStreetMap Community Forum - For broader OSM-related discussions
- OSM Slack - Join the #dev channel
Please be respectful and follow the OpenStreetMap Code of Conduct in all community interactions.
Contributing
I welcome your contributions in code, documentation and suggestions for enhancements.
If you find osmdiff useful, or you use it in commercial software, please consider sponsoring this project.
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 osmdiff-0.4.6.tar.gz.
File metadata
- Download URL: osmdiff-0.4.6.tar.gz
- Upload date:
- Size: 23.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
59e5f618f955d30deb7e6d355ecc798e77cd0f956fec2feb6c0448c0e09c7505
|
|
| MD5 |
b46db8f17db4f11a4da55e031d207a33
|
|
| BLAKE2b-256 |
aad3b8ef3e67844de69a3c7ce462c9fded248c7cb84a69f1970c5480248c061c
|
Provenance
The following attestation bundles were made for osmdiff-0.4.6.tar.gz:
Publisher:
python-publish.yml on mvexel/osmdiff
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
osmdiff-0.4.6.tar.gz -
Subject digest:
59e5f618f955d30deb7e6d355ecc798e77cd0f956fec2feb6c0448c0e09c7505 - Sigstore transparency entry: 206677946
- Sigstore integration time:
-
Permalink:
mvexel/osmdiff@311379c94337ef322074e8c72c000187c94594f9 -
Branch / Tag:
refs/tags/v0.4.6 - Owner: https://github.com/mvexel
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@311379c94337ef322074e8c72c000187c94594f9 -
Trigger Event:
release
-
Statement type:
File details
Details for the file osmdiff-0.4.6-py3-none-any.whl.
File metadata
- Download URL: osmdiff-0.4.6-py3-none-any.whl
- Upload date:
- Size: 15.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
73ac871813291f2a3cb64c9108fefe008d8f2774485e2bd557af252ae1def650
|
|
| MD5 |
461f678f1aa2dde9ecdc22ea110fbd02
|
|
| BLAKE2b-256 |
8d4cc5c96a4a3d2d6eacb8a41b0075ac01a79bd38053bef45ea2e6de8067ecce
|
Provenance
The following attestation bundles were made for osmdiff-0.4.6-py3-none-any.whl:
Publisher:
python-publish.yml on mvexel/osmdiff
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
osmdiff-0.4.6-py3-none-any.whl -
Subject digest:
73ac871813291f2a3cb64c9108fefe008d8f2774485e2bd557af252ae1def650 - Sigstore transparency entry: 206677947
- Sigstore integration time:
-
Permalink:
mvexel/osmdiff@311379c94337ef322074e8c72c000187c94594f9 -
Branch / Tag:
refs/tags/v0.4.6 - Owner: https://github.com/mvexel
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@311379c94337ef322074e8c72c000187c94594f9 -
Trigger Event:
release
-
Statement type: