Skip to main content

osmapi

Build osmapi Version License Coverage Code style: black pre-commit

Python wrapper for the OSM API (requires Python >= 3.10).

NOTE: All method names of this library are in snake_case (e.g. api.node_get(123)). The deprecated CamelCase versions (e.g. api.NodeGet(123)) were removed in version 6.0, they have been deprecated since version 5.0.

Installation

Install osmapi from PyPi by using pip:

pip install osmapi

Documentation

The documentation is generated using pdoc and can be viewed online.

The build the documentation locally, you can use

make docs

This writes the HTML to docs/, which is not committed to the repository (it is git-ignored).

This project uses GitHub Pages to publish its documentation. The online documentation is built and deployed by the publish_docs.yml GitHub Action whenever a new release is published, so it always describes the latest released version. The workflow can also be started manually from the Actions tab, optionally with a tag to build the documentation from.

Examples

To test this library, please create an account on the development server of OpenStreetMap (https://api06.dev.openstreetmap.org).

Check the examples directory to find more example code.

Read from OpenStreetMap

>>> import osmapi
>>> api = osmapi.OsmApi()
>>> print(api.node_get(123))
{'changeset': 532907, 'uid': 14298,
'timestamp': '2007-09-29T09:19:17Z',
'lon': 10.790009299999999, 'visible': True,
'version': 1, 'user': 'Mede',
'lat': 59.9503044, 'tag': {}, 'id': 123}

Write to OpenStreetMap

Writing requires an authenticated session, see OAuth authentication below for how to create one (auth.session in this example):

>>> import osmapi
>>> api = osmapi.OsmApi(api="https://api06.dev.openstreetmap.org", session=auth.session)
>>> api.changeset_create({"comment": "My first test"})
>>> print(api.node_create({"lon":1, "lat":1, "tag": {}}))
{'changeset': 532907, 'lon': 1, 'version': 1, 'lat': 1, 'tag': {}, 'id': 164684}
>>> api.changeset_close()

OAuth authentication

Username/Password authentication was shut down by OpenStreetMap in July 2024 (see official OWG announcemnt for details), the username, password and passwordfile parameters of osmapi.OsmApi were removed in version 6.0. In order to use this library, you need to use OAuth 2.0.

To use OAuth 2.0, you must register an application with an OpenStreetMap account, either on the development server or on the production server. Once this registration is done, you'll get a client_id and a client_secret that you can use to authenticate users.

Example code using cli-oauth2 on the development server, replace OpenStreetMapDevAuth with OpenStreetMapAuth to use the production server:

import osmapi
from oauthcli import OpenStreetMapDevAuth

client_id = "<client_id>"
client_secret = "<client_secret>"

auth = OpenStreetMapDevAuth(
    client_id, client_secret, ['read_prefs', 'write_api']
).auth_code()

api = osmapi.OsmApi(
    api="https://api06.dev.openstreetmap.org",
    session=auth.session
)

with api.changeset({"comment": "My first test"}) as changeset_id:
    print(f"Part of Changeset {changeset_id}")
    node1 = api.node_create({"lon": 1, "lat": 1, "tag": {}})
    print(node1)

An alternative way using the requests-oauthlib library can be found in the examples.

User agent / credit for application

To credit the application that supplies changes to OSM, an appid can be provided. This is a string identifying the application. If this is omitted "osmapi" is used.

api = osmapi.OsmApi(
    api="https://api06.dev.openstreetmap.org",
    appid="MyOSM Script"
)

If then changesets are made using this osmapi instance, they get a tag created_by with the following content: MyOSM Script (osmapi/<version>)

Example changeset of Kort using osmapi

Note about imports / automated edits

Scripted imports and automated edits should only be carried out by those with experience and understanding of the way the OpenStreetMap community creates maps, and only with careful planning and consultation with the local community.

See the Import/Guidelines and Automated Edits/Code of Conduct for more information.

Development

This project uses uv to manage its virtual env and dependencies, see the installation instructions to get it.

If you want to help with the development of osmapi, you should clone this repository and install the dependencies:

make deps

This creates a virtual env in .venv with osmapi and all its dev dependencies installed (the provided setup.sh script does the same thing). All the commands below run inside that env, there is no need to activate it manually.

You can lint the source code using this command:

make lint

And if you want to reformat the files (using the black code style) simply run:

make format

To run the tests use the following command:

make test

To build the wheel and the source distribution locally:

make build

Release

To create a new release, follow these steps (please respect Semantic Versioning):

  1. Adapt the version number in osmapi/__init__.py
  2. Update the CHANGELOG with the version
  3. Create a pull request to merge develop into main (make sure the tests pass!)
  4. Create a new release/tag on GitHub (on the main branch)
  5. The publication on PyPI happens via GitHub Actions on every tagged commit
  6. The documentation is re-generated from the tag and published to GitHub Pages by GitHub Actions, triggered by the same release

Attribution

This project was orginally developed by Etienne Chové. This repository is a copy of the original code from SVN (http://svn.openstreetmap.org/applications/utils/python_lib/OsmApi/OsmApi.py), with the goal to enable easy contribution via GitHub and release of this package via PyPI.

See also the OSM wiki: http://wiki.openstreetmap.org/wiki/Osmapi

Metadata

Release files for osmapi 6.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for osmapi 6.0.0
File Size Uploaded
osmapi-6.0.0.tar.gz 36.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for osmapi 6.0.0
File Interpreter ABI Platform
osmapi-6.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 75.7 kB

Release files / osmapi-6.0.0.tar.gz

Download URL osmapi-6.0.0.tar.gz
Size 36.4 kB
Tags Source
SHA-256 checksum
How to use checksums
c11eacbeebb4fe01915c2eaf269885f0b92673a2e38284a5294af0029d7a6a7f
BLAKE2b-256 checksum
How to use checksums
9af46b1812283b78cc2870ba1f730193fdfec90f262b60058cd0686127d14690
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 27, 2026.

Transparency log

Release files / osmapi-6.0.0-py3-none-any.whl

Download URL osmapi-6.0.0-py3-none-any.whl
Size 39.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0e41e08556a1448e458c5b64986711cb7bef03a172ef1d64ac7845efdc0cd83f
BLAKE2b-256 checksum
How to use checksums
f5cc772e547d85ea7d40fc86db2028bcb85be820eee849c88480550571661b8a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 27, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

6.0.0 This release

2 release files

5.1.0

2 release files

5.0.0

2 release files

4.3.0

2 release files

4.2.0

2 release files

4.1.0

2 release files

4.0.0

2 release files

3.1.0

2 release files

3.0.0

2 release files

2.0.2

2 release files

2.0.0

2 release files

1.3.0

1 release file

1.2.2

1 release file

1.1.0

1 release file

1.0.2

1 release file

1.0.1

1 release file

1.0.0

1 release file

0.8.1

1 release file

0.7.2

1 release file

0.7.1

1 release file

0.7.0

1 release file

0.6.2

1 release file

0.6.1

1 release file

0.6.0

1 release file

0.5.0

1 release file

0.4.2

1 release file

0.4.1

1 release file

0.4.0

1 release file

0.3.1

1 release file

0.3.0

1 release file

0.2.26

1 release file

0.2.25

1 release file

0.2.24

1 release file

0.2.23

1 release file

0.2.22

1 release file

0.2.21

1 release file

0.2.20

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page