### Get First Script Source: https://pypi.org/project/pycountry Retrieves the first script entry from the pycountry database. ```python >>> list(pycountry.scripts)[0] Script(alpha_4='Adlm', name='Adlam', numeric='166') ``` -------------------------------- ### Get Script by Name Source: https://pypi.org/project/pycountry Fetches a specific script from the database using its name. ```python >>> latin = pycountry.scripts.get(name='Latin') >>> latin Script(alpha_4='Latn', name='Latin', numeric='215') ``` -------------------------------- ### Get First Currency Source: https://pypi.org/project/pycountry Retrieves the first currency entry from the pycountry database. ```python >>> list(pycountry.currencies)[0] Currency(alpha_3='AED', name='UAE Dirham', numeric='784') ``` -------------------------------- ### Get First Language Source: https://pypi.org/project/pycountry Retrieves the first language entry from the pycountry database. ```python >>> list(pycountry.languages)[0] Language(alpha_3='aaa', name='Ghotuo', scope='I', type='L') ``` -------------------------------- ### List all countries Source: https://pypi.org/project/pycountry Import the pycountry library and access the countries database to get the total count of countries and list the first country. ```python >>> import pycountry >>> len(pycountry.countries) 249 >>> list(pycountry.countries)[0] Country(alpha_2='AW', alpha_3='ABW', flag='🇦🇼', name='Aruba', numeric='533') ``` -------------------------------- ### Get country by alpha-2 code Source: https://pypi.org/project/pycountry Retrieve specific country details using the `get` method with the alpha-2 code. This example shows how to fetch information for Germany. ```python >>> germany = pycountry.countries.get(alpha_2='DE') >>> germany Country(alpha_2='DE', alpha_3='DEU', flag='🇩🇪', name='Germany', numeric='276', official_name='Federal Republic of Germany') >>> germany.alpha_2 'DE' >>> germany.alpha_3 'DEU' >>> germany.numeric '276' >>> germany.name 'Germany' >>> germany.official_name 'Federal Republic of Germany' ``` -------------------------------- ### Get Number of Scripts Source: https://pypi.org/project/pycountry Use this to find the total number of scripts available in the pycountry database. ```python >>> len(pycountry.scripts) 226 ``` -------------------------------- ### Get Currency by Alpha-3 Code Source: https://pypi.org/project/pycountry Fetches a specific currency using its ISO 4217 alpha-3 code. ```python >>> argentine_peso = pycountry.currencies.get(alpha_3='ARS') >>> argentine_peso Currency(alpha_3='ARS', name='Argentine Peso', numeric='032') ``` -------------------------------- ### Get Language by Alpha-2 Code Source: https://pypi.org/project/pycountry Fetches a language using its ISO 639-1 alpha-2 code. ```python >>> aragonese = pycountry.languages.get(alpha_2='an') >>> aragonese.alpha_2 'an' >>> aragonese.alpha_3 'arg' >>> aragonese.name 'Aragonese' ``` -------------------------------- ### Get Language by Alpha-2 Code and Access Properties Source: https://pypi.org/project/pycountry Retrieves a language by its alpha-2 code and accesses its common name. ```python >>> bengali = pycountry.languages.get(alpha_2='bn') >>> bengali.name 'Bengali' >>> bengali.common_name 'Bangla' ``` -------------------------------- ### Get Number of Languages Source: https://pypi.org/project/pycountry Returns the total count of languages in the pycountry database. ```python >>> len(pycountry.languages) 7923 ``` -------------------------------- ### Get Number of Currencies Source: https://pypi.org/project/pycountry Find the total count of currencies available in the pycountry database. ```python >>> len(pycountry.currencies) 178 ``` -------------------------------- ### Access country attributes Source: https://pypi.org/project/pycountry Access country attributes directly using dot notation. This example demonstrates retrieving the flag and shows an `AttributeError` for non-existent attributes. ```python >>> aland = pycountry.countries.get(alpha_2='AX') >>> print(aland) Country(alpha_2='AX', alpha_3='ALA', flag='🇦🇽', name='Åland Islands', numeric='248') >>> aland.common_name Traceback (most recent call last): AttributeError: common_name >>> aland.flag '🇦🇽' >>> aland.foo Traceback (most recent call last): AttributeError: foo ``` -------------------------------- ### Access All Country Subdivisions Source: https://pypi.org/project/pycountry Get the total count of available country subdivisions and access the first subdivision in the list. Subdivisions are represented by SubdivisionHierarchy objects. ```python >>> len(pycountry.subdivisions) 5046 >>> list(pycountry.subdivisions)[0] SubdivisionHierarchy(code='AD-02', country_code='AD', name='Canillo', parent_code=None, type='Parish') ``` -------------------------------- ### Get Subdivision by Code Source: https://pypi.org/project/pycountry Retrieve a specific subdivision using its unique code. The returned object includes the code, name, type, and the associated country object. ```python >>> de_st = pycountry.subdivisions.get(code='DE-ST') >>> de_st.code 'DE-ST' >>> de_st.name 'Sachsen-Anhalt' >>> de_st.type 'Land' >>> de_st.country Country(alpha_2='DE', alpha_3='DEU', flag='🇩🇪', name='Germany', numeric='276', official_name='Federal Republic of Germany') ``` -------------------------------- ### Get Subdivisions for a Specific Country Source: https://pypi.org/project/pycountry Query and retrieve all subdivisions belonging to a particular country using its country code. This is useful for listing all administrative divisions within a country. ```python >>> len(pycountry.subdivisions.get(country_code='DE')) 16 >>> len(pycountry.subdivisions.get(country_code='US')) 57 ``` -------------------------------- ### Get Historic Country by Alpha-3 Code Source: https://pypi.org/project/pycountry Retrieve a historic country object using its 3-letter alpha code. The resulting object contains details like alpha-2, alpha-3, alpha-4 codes, name, numeric code, and withdrawal date. ```python >>> ussr = pycountry.historic_countries.get(alpha_3='SUN') >>> ussr Country(alpha_2='SU', alpha_3='SUN', alpha_4='SUHH', name='USSR, Union of Soviet Socialist Republics', numeric='810', withdrawal_date='1992-08-30') >>> ussr.alpha_4 'SUHH' >>> ussr.alpha_3 'SUN' >>> ussr.name 'USSR, Union of Soviet Socialist Republics' >>> ussr.withdrawal_date '1992-08-30' ``` -------------------------------- ### Access Currency Properties Source: https://pypi.org/project/pycountry Demonstrates accessing properties of a currency object. ```python >>> argentine_peso.alpha_3 'ARS' >>> argentine_peso.name 'Argentine Peso' >>> argentine_peso.numeric '032' ``` -------------------------------- ### Access Script Properties Source: https://pypi.org/project/pycountry Demonstrates how to access individual properties of a script object. ```python >>> latin.alpha_4 'Latn' >>> latin.name 'Latin' >>> latin.numeric '215' ``` -------------------------------- ### Add Custom Country Entry Source: https://pypi.org/project/pycountry Add a non-ISO country entry to the pycountry database at runtime. Requires alpha_2, name, and numeric codes. ```python >>> pycountry.countries.add_entry(alpha_2="XK", alpha_3="XXK", name="Kosovo", numeric="926") ``` -------------------------------- ### Fuzzy search for countries Source: https://pypi.org/project/pycountry Perform a fuzzy search for country names that might not be exact matches. This can help discover countries even with partial or slightly incorrect names. ```python >>> pycountry.countries.search_fuzzy('England') [Country(alpha_2='GB', alpha_3='GBR', flag='🇬🇧', name='United Kingdom', numeric='826', official_name='United Kingdom of Great Britain and Northern Ireland')] >>> pycountry.countries.search_fuzzy('Cote') [Country(alpha_2='CI', alpha_3='CIV', flag='🇨🇮', name="Côte d'Ivoire", numeric='384', official_name='Republic of Côte d\'Ivoire'), Country(alpha_2='FR', alpha_3='FRA', flag='🇫🇷', name='France', numeric='250', official_name='French Republic'), Country(alpha_2='HN', alpha_3='HND', flag='🇭🇳', name='Honduras', numeric='340', official_name='Republic of Honduras')] ``` -------------------------------- ### Lookup Country by Code Source: https://pypi.org/project/pycountry Find a country entity using its alpha-2 code. The search is case-insensitive and returns the first match. ```python >>> pycountry.countries.lookup('de') Country(alpha_2='DE', alpha_3='DEU', flag='🇩🇪', name='Germany', numeric='276', official_name='Federal Republic of Germany') ``` -------------------------------- ### Fuzzy Search for Subdivisions Source: https://pypi.org/project/pycountry Use the search_fuzzy method to find subdivisions when the exact name or code is unknown. This method normalizes unicode characters and prioritizes name matches, returning a list of potential subdivision matches. ```python >>> pycountry.subdivisions.search_fuzzy('York') [SubdivisionHierarchy(code='GB-YOR', country_code='GB', name='York', parent='GB-ENG', parent_code='GB-ENG', type='Unitary authority'), SubdivisionHierarchy(code='GB-ERY', country_code='GB', name='East Riding of Yorkshire', parent='GB-ENG', parent_code='GB-ENG', type='Unitary authority'), SubdivisionHierarchy(code='GB-NYK', country_code='GB', name='North Yorkshire', parent='GB-ENG', parent_code='GB-ENG', type='Two-tier county'), SubdivisionHierarchy(code='US-NY', country_code='US', name='New York', parent_code=None, type='State')] ``` -------------------------------- ### Access Subdivision Parent Information Source: https://pypi.org/project/pycountry Retrieve a subdivision and access its parent information, including the parent code and the parent subdivision object. This demonstrates the hierarchical nature of subdivisions. ```python >>> fr_01 = pycountry.subdivisions.get(code='FR-01') >>> fr_01.code 'FR-01' >>> fr_01.name 'Ain' >>> fr_01.type 'Metropolitan department' >>> fr_01.parent_code 'FR-ARA' >>> fr_01.parent SubdivisionHierarchy(code='FR-ARA', country_code='FR', name='Auvergne-Rhône-Alpes', parent_code=None, type='Metropolitan region') >>> fr_01.parent.name 'Auvergne-Rhône-Alpes' ``` -------------------------------- ### Translate Country Name to German Source: https://pypi.org/project/pycountry Uses Python's gettext module with pycountry locale data to translate 'Germany' into German. ```python >>> import gettext >>> german = gettext.translation('iso3166-1', pycountry.LOCALES_DIR, ... languages=['de']) >>> german.install() >>> _('Germany') 'Deutschland' ``` -------------------------------- ### Convert Country Object to Dictionary Source: https://pypi.org/project/pycountry Cast a country object obtained from a lookup into a Python dictionary for easier data manipulation. ```python >>> country = pycountry.countries.lookup('de') >>> dict(country) {'alpha_2': 'DE', 'alpha_3': 'DEU', 'flag': '🇩🇪', 'name': 'Germany', 'numeric': '276', 'official_name': 'Federal Republic of Germany'} ``` -------------------------------- ### Remove Country Entry Source: https://pypi.org/project/pycountry Remove a country entry from the pycountry database using its alpha-2 code. This is useful for managing custom entries. ```python >>> pycountry.countries.remove_entry(alpha_2="XK") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.