Skip to main content

Share structured common data in a pythonic way

Project description

Share structured common data in a pythonic way

The library just provides pure data, it does not feature any querying or rendering functionality. This is a design choice. This data is meant to be imported into existing systems that use their own preferences for rendering and querying data.

Online version of this document on https://github.com/lsaffre/commondata

Countries of the world

>>> from commondata.countries import COUNTRIES, FIELDS
>>> FIELDS
('entity', 'name', 'isoCode2', 'isoCode3', 'zipCode', 'population')
>>> COUNTRIES[0]
Country(entity='Q228', name={'en': 'Andorra', 'de': 'Andorra', 'fr': 'Andorre', 'nl': 'Andorra', 'et': 'Andorra', 'bn': 'অ্যান্ডোরা', 'es': 'Andorra'}, isoCode2='AD', isoCode3='AND', zipCode=None, population='87097')
>>> len(COUNTRIES)
195

These are the countries of the world:

>>> lst = ["{} ({})".format(c.name['en'], c.isoCode2) for c in COUNTRIES]
>>> print(", ".join(lst))  #doctest: +REPORT_UDIFF +NORMALIZE_WHITESPACE
Andorra (AD), United Arab Emirates (AE), Afghanistan (AF), Antigua and Barbuda
(AG), Albania (AL), Armenia (AM), Angola (AO), Argentina (AR), Austria (AT),
Australia (AU), Azerbaijan (AZ), Bosnia and Herzegovina (BA), Barbados (BB),
Bangladesh (BD), Belgium (BE), Burkina Faso (BF), Bulgaria (BG), Bahrain (BH),
Burundi (BI), Benin (BJ), Brunei (BN), Bolivia (BO), Brazil (BR), The Bahamas
(BS), Bhutan (BT), Botswana (BW), Belarus (BY), Belize (BZ), Canada (CA),
Democratic Republic of the Congo (CD), Central African Republic (CF), Republic
of the Congo (CG), Switzerland (CH), Ivory Coast (CI), Chile (CL), Cameroon
(CM), People's Republic of China (CN), Colombia (CO), Costa Rica (CR), Cuba
(CU), Cape Verde (CV), Cyprus (CY), Czech Republic (CZ), Germany (DE), Djibouti
(DJ), Dominica (DM), Dominican Republic (DO), Algeria (DZ), Ecuador (EC),
Estonia (EE), Egypt (EG), Eritrea (ER), Spain (ES), Ethiopia (ET), Finland (FI),
Fiji (FJ), Federated States of Micronesia (FM), France (FR), Gabon (GA), United
Kingdom (GB), Grenada (GD), Georgia (GE), Ghana (GH), The Gambia (GM), Guinea
(GN), Equatorial Guinea (GQ), Greece (GR), Guatemala (GT), Guinea-Bissau (GW),
Guyana (GY), Honduras (HN), Croatia (HR), Haiti (HT), Hungary (HU), Indonesia
(ID), Ireland (IE), Israel (IL), India (IN), Iraq (IQ), Iran (IR), Iceland (IS),
Italy (IT), Jamaica (JM), Jordan (JO), Japan (JP), Kenya (KE), Kyrgyzstan (KG),
Cambodia (KH), Kiribati (KI), Comoros (KM), Saint Kitts and Nevis (KN), North
Korea (KP), South Korea (KR), Kuwait (KW), Kazakhstan (KZ), Laos (LA), Lebanon
(LB), Saint Lucia (LC), Liechtenstein (LI), Sri Lanka (LK), Liberia (LR),
Lesotho (LS), Lithuania (LT), Luxembourg (LU), Latvia (LV), Libya (LY), Morocco
(MA), Monaco (MC), Moldova (MD), Montenegro (ME), Madagascar (MG), Marshall
Islands (MH), North Macedonia (MK), Mali (ML), Myanmar (MM), Mongolia (MN),
Mauritania (MR), Malta (MT), Mauritius (MU), Maldives (MV), Malawi (MW), Mexico
(MX), Malaysia (MY), Mozambique (MZ), Namibia (NA), Niger (NE), Nigeria (NG),
Nicaragua (NI), Kingdom of the Netherlands (NL), Norway (NO), Nepal (NP), Nauru
(NR), New Zealand (NZ), Oman (OM), Panama (PA), Peru (PE), Papua New Guinea
(PG), Philippines (PH), Pakistan (PK), Poland (PL), Palestine (PS), Portugal
(PT), Palau (PW), Paraguay (PY), Qatar (QA), Romania (RO), Serbia (RS), Russia
(RU), Rwanda (RW), Saudi Arabia (SA), Solomon Islands (SB), Seychelles (SC),
Sudan (SD), Sweden (SE), Singapore (SG), Slovenia (SI), Slovakia (SK), Sierra
Leone (SL), San Marino (SM), Senegal (SN), Somalia (SO), Suriname (SR), South
Sudan (SS), São Tomé and Príncipe (ST), El Salvador (SV), Syria (SY), Eswatini
(SZ), Chad (TD), Togo (TG), Thailand (TH), Tajikistan (TJ), Timor-Leste (TL),
Turkmenistan (TM), Tunisia (TN), Tonga (TO), Turkey (TR), Trinidad and Tobago
(TT), Tuvalu (TV), Taiwan (TW), Tanzania (TZ), Ukraine (UA), Uganda (UG), United
States (US), Uruguay (UY), Uzbekistan (UZ), Vatican City (VA), Saint Vincent and
the Grenadines (VC), Venezuela (VE), Vietnam (VN), Vanuatu (VU), Samoa (WS),
Yemen (YE), South Africa (ZA), Zambia (ZM), Zimbabwe (ZW)

Place names in Estonia

>>> from commondata.places.estonia import PLACES, COUNTIES
>>> len(PLACES)
4564
>>> len(COUNTIES)
15
>>> for county in COUNTIES:
...    print(county.name, ":", ", ".join([p.name for p in county.children]))
Harju : Tallinn, Ääsmäe, Loksa, Vasalemma, Nissi, Saku, Saue, Viimsi, Raasiku, Jõelähtme, Maardu, Rae, Harku, Keila, Anija, Kehra, Kiili, Paldiski, Kose, Padise, Kõue, Kuusalu, Kernu, Aegviidu, Kaasiku, Kibuna, Vahastu, Vansi, Vikipalu, Jägala-Joa, Kersalu, Haapse, Jõesuu, Pohla, Andineeme
Pärnu : Pärnu, Halinga, Tootsi, Vändra, Tori, Tõstamaa, Tahkuranna, Sauga, Paikuse, Sindi, Audru, Häädemeeste, Kilingi-Nõmme, Are, Lavassaare, Varbla, Saarde, Surju, Kihnu, Koonga, Metsaääre, Aruvälja
Rapla : Vigala, Rapla, Kehtna, Märjamaa, Järvakandi, Juuru, Kaiu, Käru, Kohila, Raikküla
Hiiu : Kärdla, Käina, Kõrgessaare, Pühalepa, Emmaste
Ida-Viru : Lohusuu, Sonda, Toila, Tudulinna, Sillamäe, Püssi, Lüganuse, Vaivara, Narva, Avinurme, Narva-Jõesuu, Kohtla-Järve, Aseri, Jõhvi, Iisaku, Kiviõli, Alajõe, Kohtla-Nõmme, Maidla, Mäetaguse, Kohtla, Illuka
Jõgeva : Torma, Põltsamaa, Tabivere, Mustvee, Jõgeva, Palamuse, Puurmani, Saare, Kasepää, Pajusi, Pala, Vägeva
Järva : Türi, Roosna-Alliku, Paide, Väätsa, Ambla, Järva-Jaani, Koeru, Kareda, Albu, Imavere, Koigi, Kolu
Lääne : Lihula, Risti, Ridala, Haapsalu, Hanila, Taebla, Oru, Vormsi, Martna, Noarootsi, Nõva, Kullamaa
Lääne-Viru : Tapa, Rakvere, Vinni, Tamsalu, Rakke, Väike-Maarja, Sõmeru, Vihula, Haljala, Kunda, Kadrina, Laekvere, Viru-Nigula, Eisma
Põlva : Räpina, Põlva, Veriora, Kanepi, Ahja, Kõlleste, Vastse-Kuuste, Värska, Mikitamäe, Mooste, Orava, Valgjärve, Laheda
Saare : Leisi, Salme, Kaarma, Orissaare, Kärla, Kihelkonna, Kuressaare, Valjala, Lümanda, Pöide, Pihtla, Torgu, Mustjala, Laimjala, Muhu, Ruhnu
Tartu : Tartu, Luunja, Ülenurme, Haaslava, Rõngu, Kambja, Elva, Nõo, Kallaste, Puhja, Alatskivi, Mäksa, Tähtvere, Konguta, Rannu, Laeva, Võnnu, Peipsiääre, Meeksi, Vara, Piirissaare, Vehendi, Kriimani, Illi, Neemisküla
Valga : Valga, Tõrva, Otepää, Puka, Õru, Tõlliste, Sangaste, Karula, Helme, Taheva, Põdrala, Palupera, Hummuli
Viljandi : Suure-Jaani, Abja, Abja-Paluoja, Viljandi, Võhma, Mõisaküla, Viiratsi, Halliste, Karksi, Karksi-Nuia, Kolga-Jaani, Pärsti, Tarvastu, Saarepeedi, Paistu, Kõpu, Kõo, Soe
Võru : Vastseliina, Võru, Antsla, Varstu, Sõmerpalu, Rõuge, Mõniste, Haanja, Urvaste, Lasva, Misso, Meremäe, Kirumpää, Navi, Meegomäe

Note: The data about Estonian places is currently obsolete by several years. We plan to maintain it in collaboration with https://maaamet.ee/ruumiandmed-ja-kaardid/aadressid-ja-kohanimed/kohanimeregister

Historic note

Until March 2024 this was a namespace package and country-specific data was contained in individual subpackages. The following packages are now obsolete

How to uninstall the old commondata packages: find your site-packages directory (e.g. ~/env/lib/python3.10/site-packages) and manually remove all files commondata*-nspkg.pth

Don’t read on

The remaining part of this document is obsolete but still valid.

How to use the Place and PlaceGenerator classes.

You define a subclass of Place for each “type” of place:

>>> from commondata.utils import Place, PlaceGenerator
>>> class PlaceInFoo(Place):
...     def __str__(self):
...        return self.name
>>> class Kingdom(PlaceInFoo):
...     value = 1
>>> class County(PlaceInFoo):
...     value = 2
>>> class Borough(PlaceInFoo):
...     value = 3
>>> class Village(PlaceInFoo):
...     value = 3

The PlaceGenerator is used to instantiate to populate

Part 1 : configuration:

>>> pg = PlaceGenerator()
>>> pg.install(Kingdom, County, Borough, Village)
>>> pg.set_args('name')

Part 2 : filling data

>>> root = pg.kingdom("Kwargia")
>>> def fill(pg):
...    pg.county("Kwargia")
...    pg.borough("Kwargia")
...    pg.village("Virts")
...    pg.village("Vinks")
...    pg.county("Gorgia")
...    pg.village("Girts")
...    pg.village("Ginks")
>>> fill(pg)

Part 3 : using the data

>>> [str(x) for x in root.children]
['Kwargia', 'Gorgia']
>>> kwargia = root.children[0]
>>> [str(x) for x in kwargia.children]
['Kwargia', 'Virts', 'Vinks']

Multilingual place names

You use the commondata.utils.PlaceGenerator.set_args() method to specify the names of the fields of subsequent places.

>>> pg = PlaceGenerator()
>>> pg.install(Kingdom, County, Borough, Village)
>>> pg.set_args('name name_ar')
>>> root = pg.kingdom("Egypt", u'مصر')
>>> print(root.name_ar)
مصر

Peppol codes

The commondata.peppol module defines a dict COUNTRY2SCHEME, which maps country codes to the EAS number of their VAT office.

This module has been generated from https://docs.peppol.eu/edelivery/codelists

>>> from commondata.peppolcodes import COUNTRY2SCHEME
>>> COUNTRY2SCHEME['BE']
'9925'
>>> COUNTRY2SCHEME['EE']
'9931'

Not every country has an Electronic Address Scheme:

>>> COUNTRY2SCHEME['US']
Traceback (most recent call last):
...
KeyError: 'US'

Here is a list of the Peppol countries:

>>> " ".join(sorted(COUNTRY2SCHEME.keys()))
'AD AL AT BA BE BG CH CY CZ DE EE ES FI FR GB GR HR HU IE IT LI LT LU LV MC ME MK MT NL NO PL PT RO RS SE SI SK SM TR VA international'

This is used by Lino, see https://dev.lino-framework.org/topics/peppol.html#electronic-address-scheme

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

commondata-25.2.0.tar.gz (141.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

commondata-25.2.0-py2.py3-none-any.whl (135.0 kB view details)

Uploaded Python 2Python 3

File details

Details for the file commondata-25.2.0.tar.gz.

File metadata

  • Download URL: commondata-25.2.0.tar.gz
  • Upload date:
  • Size: 141.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for commondata-25.2.0.tar.gz
Algorithm Hash digest
SHA256 3c70104a7b95aaaeaead0316877415814ecbebdb449caedd6e1aea651435052b
MD5 0387394aa11555a8696e753bbb1d64cf
BLAKE2b-256 89f0506f9ba59367f8d495c79a640c5cb861e2fad058be417c344a2c3db1872a

See more details on using hashes here.

File details

Details for the file commondata-25.2.0-py2.py3-none-any.whl.

File metadata

  • Download URL: commondata-25.2.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 135.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for commondata-25.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 e48eac8dad0b0a46efbe40b09b563d2ba1ac44cc7e09419ab5fd9276279dfdc0
MD5 775858417b279f2261fb5283b1be051f
BLAKE2b-256 ee08d6df27ee80ec8b3eeeb1c87cade04d42ce0450f9cd6343e76f3b84e9d7d9

See more details on using hashes here.

Supported by

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