Home

Awesome

<!-- Copyright (c) 2021 kraptor This software is released under the MIT License. https://opensource.org/licenses/MIT -->

made-with-nim Build

isocodes

ISO codes for Nim.

Supports loading the data at runtime or embedding it within the executable

Provides the utility isocodes_download to download latest JSON packages when you don't want to use the provided ones (or if they become obsolete).

By default all data is embedded within the executable. See section Compilation flags on how to specify the files to load/embed and how to load the data at runtime if you need to.

Supported ISO standards

ISODescriptionLibrary type
ISO 3166-1Name of countriesCountry
ISO 3166-2Country subdivisionsCountrySubdivision
ISO 3166-3Countries removed from the standard.RemovedCountry
ISO 15924Language scriptsScript
ISO 4217CurrenciesCurrency
ISO 639-2LanguagesLanguage
ISO 639-5Language FamiliesLanguageFamily

Example

    import isocodes

    if isMainModule:
        for c in Country.allIt():
            echo c.name

API

All procedures/iterators can be accessed by using the corresponding type. For example: Country.

Procedures either return an Option[T] object or a seq[T] (when multiple values can be requested).

IMPORTANT: Procedures ending in It return an iterator, instead of a seq[T], if you don't want to store/build a copy of the data requested.

Country API

Country Attributes

The following attributes are available for each Country instance:

AttributeDescription
nameCountry name.
official_nameOfficial name of the country.
common_nameCommon name for the country.
alpha_2Country ISO code (2 characters).
alpha_3Country ISO code (3 characters).
numericNumeric code for the country. NOTE: this is a string.
flagFlag emoji for the country.

Country Procedures

ProcedureDescription
.count()Number of countries
.all()seq for all countries.
.allIt()Iterator for all countries.
.byName(str)Option[Country] with the specified name.
.byAlpha2(str)Option[Country] with the specified alpha2 code.
.byAlpha3(str)Option[Country] with the specified alpha3 code.
.byNumeric(str)Option[Country] with the specified numeric code.
.byOfficialName(str)Option[Country] with the specified official name.
.byCommonName(str)Option[Country] with the specified common name.
.find(proc)seq for all countries that proc evaluates to true.
.findIt(proc)Iterator for all countries that proc evaluates to true.
.findFirst(proc)Option[Country] were proc evaluates to true.

CountrySubdivision API

CountrySubdivision Attributes

AttributeDescription
codeSubdivision code.
nameName of the subdivision.
typeType of the subdivision.<br />NOTE: use stropping to access this field because type is a reserved word.<br />Example: echo subdivision.`type` .
parentParent code.

CountrySubdivision Procedures

ProcedureDescription
.count()Number of subdivisions
.all()seq for all subdivisions.
.allIt()Iterator for all subdivisions.
.byCountryCode(str)seq for subdivisions for an specific country code.
.byCountryCodeIt(str)Iterator for subdivisions for an specific country code.
.byCode(str)seq for subdivisions by specified code.
.byCodeIt(str)Iterator for subdivisions specified by code.
.byCodeStart(str)seq for subdivisions where code starts by a value.
.byCodeStartIt(str)Iterator subdivisions where code starts by a value.
.byName(str)seq for subdivisions with specified name.
.byNameIt(str)Iterator for subdivisions with specified name.
.byType(str)seq for subdivisions with the specified type.
.byTypeIt(str)Iterator for subdivisions with the specified type.
.byParent(str)seq for subdivisions with the specified parent value.
.byParentIt(str)Iterator for subdivisions with the specified parent value.
.find(proc)seq for all subdivisions that proc evaluates to true.
.findIt(proc)Iterator for all subdivisions that proc evaluates to true.
.findFirst(proc)Option[CountrySubdivision] were proc evaluates to true.

RemovedCountry API

RemovedCountry Attributes

AttributeDescription
nameCountry name.
official_nameOfficial name of the country.
alpha_2Country ISO code (2 characters).
alpha_3Country ISO code (3 characters).
alpha_4Country ISO code (4 characters).
numericNumeric code for the country. <br/> NOTE: this is a string.
commentComment about the country.
withdrawal_dateDate of withdrawal (format: YYYY or YYYY-MM-DD) <br/> NOTE: this is a string.

RemovedCountry Procedures

ProcedureDescription
.count()Number of countries
.all()seq for all countries.
.allIt()Iterator for all countries.
.byName(str)Option[Country] with the specified name.
.byAlpha2(str)Option[Country] with the specified alpha2 code.
.byAlpha3(str)Option[Country] with the specified alpha3 code.
.byAlpha4(str)Option[Country] with the specified alpha4 code.
.byNumeric(str)Option[Country] with the specified numeric code.
.byWithdrawalDate(str)seq for all countries with specified date.
.byWithdrawalDateIt(str)Iterator all countries with specified date.
.byWithdrawalYear(str)seq for all countries with specified year.
.byWithdrawalYearIt(str)Iterator all countries with specified year.
.find(proc)seq for all countries that proc evaluates to true.
.findIt(proc)Iterator for all countries that proc evaluates to true.
.findFirst(proc)Option[Country] were proc evaluates to true.

Script API

Script Attributes

AttributeDescription
nameScript name.
alpha_4Script ISO code (4 characters).
numericNumeric code for the script. <br/> NOTE: this is a string.

Script Procedures

ProcedureDescription
.count()Number of scripts
.all()seq for all scripts.
.allIt()Iterator for all scripts.
.byName(str)Option[Script] with the specified name.
.byAlpha4(str)Option[Script] with the specified alpha4 code.
.byNumeric(str)Option[Script] with the specified numeric code.
.find(proc)seq for all scripts that proc evaluates to true.
.findIt(proc)Iterator for all scripts that proc evaluates to true.
.findFirst(proc)Option[Script] were proc evaluates to true.

Currency API

Currency Attributes

AttributeDescription
nameCurrency name.
alpha_3Currency ISO code (3 characters).
numericNumeric code for the currency. <br/> NOTE: this is a string.

Currency Procedures

ProcedureDescription
.count()Number of currencies.
.all()seq for all currencies.
.allIt()Iterator for all currencies.
.byName(str)Option[Currency] with the specified name.
.byAlpha3(str)Option[Currency] with the specified alpha3 code.
.byNumeric(str)Option[Currency] with the specified numeric code.
.find(proc)seq for all currencies that proc evaluates to true.
.findIt(proc)Iterator for all currencies that proc evaluates to true.
.findFirst(proc)Option[Currency] were proc evaluates to true.

Language API

Language Attributes

AttributeDescription
nameLanguage name.
alpha_2Language ISO code (2 characters).
alpha_3Language ISO code (3 characters).
common_nameLanguage common name.
bibliographicLanguage bibliographic code.

Language Procedures

ProcedureDescription
.count()Number of languages.
.all()seq for all languages.
.allIt()Iterator for all languages.
.byName(str)Option[Language] with the specified name.
.byCommonName(str)Option[Language] with the specified common name.
.byAlpha2(str)Option[Language] with the specified alpha2 code.
.byAlpha3(str)Option[Language] with the specified alpha3 code.
.byBibliographic(str)Option[Language] with the specified bibliographic code.
.find(proc)seq for all languages that proc evaluates to true.
.findIt(proc)Iterator for all languages that proc evaluates to true.
.findFirst(proc)Option[Language] were proc evaluates to true.

LanguageFamily API

LanguageFamily Attributes

AttributeDescription
nameLanguage family name.
alpha_3Language family ISO code (3 characters).

LanguageFamily Procedures

ProcedureDescription
.count()Number of language families.
.all()seq for all language families.
.allIt()Iterator for all language families.
.byName(str)Option[LanguageFamily] with the specified name.
.byAlpha3(str)Option[LanguageFamily] with the specified alpha3 code.
.find(proc)seq for all language families that proc evaluates to true.
.findIt(proc)Iterator for all language families that proc evaluates to true.
.findFirst(proc)Option[LanguageFamily] were proc evaluates to true.

Compilation flags

With the following flags it's possible to embed the data (or not) and specify the JSON file to embed/load. This could be useful if the provided files are outdated and you want to provide your own files, or if you want to load the data at runtime.

FlagComment
Countries
-d:embedCountries=trueEmbed countries data within the executable.
-d:embedCountries=falseLoad countries data at runtime.
-d:useCountriesFile=PATHUse a specific countries JSON file.
Country Subdivisions
-d:embedSubdivisions=trueEmbed subdivisions data within the executable.
-d:embedSubdivisions=falseLoad subdivisions data at runtime.
-d:useSubdivisionsFile=PATHUse a specific subdivisions JSON file.
Removed Countries
-d:embedRemovedCountries=trueEmbed removed countries data within the executable.
-d:embedRemovedCountries=falseLoad removed countries data at runtime.
-d:useRemovedCountriesFile=PATHUse a specific removed countries JSON file.
Scripts
-d:embedScripts=trueEmbed scripts data within the executable.
-d:embedScripts=falseLoad scripts data at runtime.
-d:useScriptsFile=PATHUse a specific scripts JSON file.
Currencies
-d:embedCurrencies=trueEmbed currencies data within the executable.
-d:embedCurrencies=falseLoad currencies data at runtime.
-d:useCurrenciesFile=PATHUse a specific currencies JSON file.
Language
-d:embedLanguages=trueEmbed languages data within the executable.
-d:embedLanguages=falseLoad languages data at runtime.
-d:useLanguagesFile=PATHUse a specific languages JSON file.
Language Families
-d:embedLanguageFamilies=trueEmbed language families data within the executable.
-d:embedLanguageFamilies=falseLoad language families data at runtime.
-d:useLanguageFamiliesFile=PATHUse a specific language families JSON file.

Source

The ISO codes JSON files are synced verbatim from Debian's iso-codes repository here: