Skip to main content

A small wrapper around taginfo API

Project description

Taginfo

This project exists to access magnificent taginfo maintained by Jochen Topf.

It is an unofficial Python wrapper over available API.

It is a Python wrapper for a tiny part of taginfo API that I use in my projects.

Note that the taginfo API is intended for the use of the OpenStreetMap community. Do not use it for other purposes. (source) As taginfo is open source you can deploy own service of needed.

Installation

Like any other python package: pip install taginfo

Examples

How often given key is used?

import taginfo

key = "name:ab"
print(key, "is used", taginfo.query.count_appearances_of_key(key), "times")

What about tags?

import taginfo

key = "horse"
value = "noo"
print(key, "=", value, "is used", taginfo.query.count_appearances_of_tag(key, value), "times")
value = "no"
print(key, "=", value, "is used", taginfo.query.count_appearances_of_tag(key, value), "times")

Listing popular values for key

import taginfo

key = "bin"
print("all values of specific key:")
for value in taginfo.query.values_of_key(key):
    print(key, "=", value)
print()
key = "surface"
print("all popular values of specific key:")
for entry in taginfo.query.values_of_key_with_data(key):
    if(entry['count'] > 1000):
        print(key, "=", entry['value'], str(int(entry['count']/1000)) + "k")

Listing popular tags unsupported by iD

See https://github.com/openstreetmap/id-tagging-schema/issues/529 - this is actually used by iD project

See test_tags_used_in_project in tests.py

Listing popular keys not supported by iD

# no issue created for it at https://github.com/openstreetmap/id-tagging-schema/issues
# right now it provides no useful info (more entries need to be skipped or verified)
project = "id_editor"
supported = []
threshold = 500_000
expected_support = []
for entry in taginfo.query.tagging_used_by_project(project):
    if entry["key"] not in supported:
        supported.append(entry["key"]) # will not catch cases where only specific value is supported
page = 1
finished = False
while not finished:
    for entry in taginfo.query.get_page_of_all_keys_with_wiki_page(page):
        if(entry['count_all'] < threshold):
            finished = True
            break
        key = entry["key"]
        banned_key_prefix_indicating_import_garbage = ["tiger:", "nhd:", "NHD:", "lacounty:", "ref:", "nysgissam:", "nycdoitt:", "yh:", "building:ruian:", "gnis:", "osak:", "maaamet:", "chicago:", "LINZ:"]
        matches_blacklisted = False
        for prefix in banned_key_prefix_indicating_import_garbage:
            if key.find(prefix) == 0:
                matches_blacklisted = True
                break
        if matches_blacklisted:
            continue
        if key in [
            "created_by", # deprecated/discardable, not listed in iD taginfo project
            "is_in", # deprecated and unwanted
            "name_1", # weird tagging promoted by old iD versions
            "addr:TW:dataset", # unwanted import tag
        ]:
            continue
        if key not in supported:
            formatted_count = str(int(entry["count_all"]/1000))+"k"
            print(key, formatted_count)
            expected_support.append({"key": key, "count": formatted_count})
    page += 1

for entry in expected_support:
    link = "https://taginfo.openstreetmap.org/keys/" + entry["key"]
    text = "`" + entry["key"] + "` " + entry["count"]
    linked_markdown_text = "[" + text + "](" + link + ")"
    print(linked_markdown_text)

Historic data

import taginfo

print("Intended to show useful info (and maybe motivate you to talk to this mappers and ask whether they meant surface=concrete:")
print(taginfo.query.count_new_appearances_of_tag_historic_data("surface", "cement", 60), "net change for surface=cement within last 60 days (this tag appears to be duplicating surface=concrete)")
print()
print("intended to show that such short-term queries are likely to be a problem, as taginfo may have delay in updating and last few days may be often unavailable:")
print(taginfo.query.count_new_appearances_of_key_historic_data("building", 1), "new building=* objects since yesterday")

Development

Contributions are welcome to cover larger part of taginfo API.

Run tests

python3 -m unittest

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

taginfo-0.0.4.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

taginfo-0.0.4-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file taginfo-0.0.4.tar.gz.

File metadata

  • Download URL: taginfo-0.0.4.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.10

File hashes

Hashes for taginfo-0.0.4.tar.gz
Algorithm Hash digest
SHA256 b9d32f04c91faaed8b87d4ebd68563c502db0f4640e097c40b5d45fcf9fbf00f
MD5 fc7525fa68cbddc27014f37359a3332d
BLAKE2b-256 ebf42305e81cb91a87669a9f25f6f5138279007480a7c449fb13a6afbb81f8fa

See more details on using hashes here.

File details

Details for the file taginfo-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: taginfo-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.10

File hashes

Hashes for taginfo-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 13ce5be4546eb2d47cc759272533665722d9ff7b6b344ce11aa1862dd1be9448
MD5 89af842968bfd2524c65b698f80db004
BLAKE2b-256 64d87e2cb7a37846a6d87c6e2c2c6d80ad3d3baa1fe450bad23d3ecfb009ba18

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page