### Install Countryinfo Library Source: https://github.com/porimol/countryinfo/blob/main/README.md Installs the Countryinfo library using pip or Poetry. Optional extras like 'fuzzy' for typo-tolerant lookups and 'pydantic' for typed models can be included. Installation from source is also supported. ```bash pip install countryinfo # With optional extras: pip install "countryinfo[fuzzy]" # typo-tolerant country lookup pip install "countryinfo[pydantic]" # Pydantic v2 typed models pip install "countryinfo[all]" # everything above # Using Poetry: poetry add countryinfo poetry add "countryinfo[fuzzy,pydantic]" # Install from source: git clone https://github.com/porimol/countryinfo.git cd countryinfo poetry install ``` -------------------------------- ### Quick Start with Countryinfo Source: https://github.com/porimol/countryinfo/blob/main/README.md Demonstrates basic usage of the Countryinfo library to retrieve information about a specific country. It shows how to instantiate the CountryInfo object and access attributes like capital, ISO code, population, and neighbors. ```python from countryinfo import CountryInfo country = CountryInfo("Singapore") print(country.capital()) # Singapore print(country.iso(2)) # SG print(country.population()) # 5469700 print(country.neighbors()) # [] — island, no land borders ``` -------------------------------- ### GET .info() Source: https://github.com/porimol/countryinfo/blob/main/README.md Retrieves the complete dataset available for the initialized country. ```APIDOC ## GET .info() ### Description Returns a dictionary containing all available metadata for the country, including ISO codes, area, population, capital, and more. ### Response #### Success Response (200) - **data** (dict) - A dictionary containing keys like 'name', 'ISO', 'area', 'capital', 'currencies', etc. ### Response Example { "name": "Singapore", "ISO": {"alpha2": "SG", "alpha3": "SGP", "numeric": "702"}, "population": 5469700 } ``` -------------------------------- ### GET .iso() Source: https://github.com/porimol/countryinfo/blob/main/README.md Retrieves ISO 3166-1 codes for the country. ```APIDOC ## GET .iso() ### Description Returns ISO 3166-1 codes. Optionally accepts an integer parameter (2 or 3) to return a specific code format. ### Parameters #### Query Parameters - **version** (int) - Optional - Specify 2 for alpha-2 or 3 for alpha-3. ### Response #### Success Response (200) - **iso_data** (dict/string) - Returns a dictionary of all codes or a specific string if version is provided. ``` -------------------------------- ### GET .borders() Source: https://github.com/porimol/countryinfo/blob/main/README.md Retrieves the list of bordering countries. ```APIDOC ## GET .borders() ### Description Returns a list of bordering countries identified by their ISO alpha-3 codes. ### Response #### Success Response (200) - **borders** (list) - A list of strings representing ISO alpha-3 codes of neighboring countries. ``` -------------------------------- ### GET /countryinfo/info Source: https://github.com/porimol/countryinfo/blob/main/README.md Retrieves comprehensive information about a specific country using the CountryInfo class constructor. ```APIDOC ## GET /countryinfo/info ### Description Initializes the country object and retrieves all available geographic and demographic data for the specified country name. ### Method GET ### Endpoint CountryInfo(name) ### Parameters #### Path Parameters - **name** (string) - Required - The common name of the country (e.g., "Singapore") ### Request Example ```python from countryinfo import CountryInfo country = CountryInfo("Singapore") ``` ### Response #### Success Response (200) - **data** (object) - Returns a dictionary containing capital, population, ISO codes, currencies, and more. #### Response Example { "capital": "Singapore", "population": 5469700, "iso": {"alpha2": "SG", "alpha3": "SGP"} } ``` -------------------------------- ### GET /countryinfo/filter Source: https://github.com/porimol/countryinfo/blob/main/README.md Provides utility methods to list or filter countries based on specific criteria. ```APIDOC ## GET /countryinfo/filter ### Description Allows for querying the entire dataset to retrieve lists of all countries or filter them based on specific attributes. ### Method GET ### Endpoint CountryInfo.all() / filter_countries() ### Parameters #### Query Parameters - **criteria** (dict) - Optional - Key-value pairs to filter countries by (e.g., region, subregion) ### Request Example ```python from countryinfo import CountryInfo # Get all countries all_data = CountryInfo.all() ``` ### Response #### Success Response (200) - **result** (list) - A list of country objects or names matching the criteria. #### Response Example [ "Afghanistan", "Albania", "Algeria" ] ``` -------------------------------- ### Initialize CountryInfo Instance Source: https://github.com/porimol/countryinfo/blob/main/README.md Demonstrates how to create a CountryInfo instance using various identifiers including English names, ISO alpha-2/alpha-3 codes, and ISO numeric codes. The constructor is case-insensitive and raises exceptions for invalid inputs. ```python from countryinfo import CountryInfo # Initialization examples CountryInfo("Singapore") CountryInfo("SG") CountryInfo("SGP") CountryInfo(702) # Accessing data sg = CountryInfo("SG") print(sg.info()) ``` -------------------------------- ### Constructor - Initialize CountryInfo Source: https://github.com/porimol/countryinfo/blob/main/README.md Initializes a new CountryInfo instance. Accepts various country identifiers including English names, ISO alpha-2/alpha-3 codes, or ISO numeric codes. ```APIDOC ## Constructor ### Description Creates an instance of CountryInfo for a specific country using a variety of identifier formats. ### Parameters #### Path Parameters - **identifier** (string/int) - Required - The country identifier (e.g., "Singapore", "SG", "SGP", "702"). ### Request Example ```python country = CountryInfo("SG") ``` ### Response #### Success Response - **instance** (Object) - A CountryInfo object ready for data retrieval. #### Error Handling - **ValueError**: Raised if no identifier is provided. - **CountryNotFoundError**: Raised if the identifier cannot be resolved. ``` -------------------------------- ### Running project tests Source: https://github.com/porimol/countryinfo/blob/main/README.md Command to execute the test suite for the project using poetry and pytest. ```bash poetry run pytest tests/ -v ``` -------------------------------- ### CLI usage for country data retrieval Source: https://github.com/porimol/countryinfo/blob/main/README.md Demonstrates how to use the countryinfo command-line interface to query specific fields, filter countries by attributes, and output results in JSON format. ```bash countryinfo Singapore --field capital countryinfo SG --field iso countryinfo 702 --field current_utc_offset countryinfo --filter region=Asia countryinfo --filter currency=EUR countryinfo --filter region=Europe currency=EUR countryinfo Singapore --json countryinfo --filter language=ar --json ``` -------------------------------- ### Manage Timezone Information Source: https://github.com/porimol/countryinfo/blob/main/README.md Methods for retrieving static UTC offsets, IANA timezone names, and current DST-aware UTC offsets for specific countries. ```python country = CountryInfo("Singapore") print(country.timezones()) print(country.timezone_names()) print(country.current_utc_offset()) ``` -------------------------------- ### Handling CountryInfo lookup errors Source: https://github.com/porimol/countryinfo/blob/main/README.md Shows how to catch CountryNotFoundError and ValueError exceptions when initializing CountryInfo with invalid or empty inputs in Python. ```python from countryinfo import CountryInfo, CountryNotFoundError try: country = CountryInfo("Xanadu") except CountryNotFoundError as e: print(e) try: CountryInfo(None) except ValueError: pass ``` -------------------------------- ### Fuzzy Lookup and Pydantic Integration Source: https://github.com/porimol/countryinfo/blob/main/README.md Optional features including typo-tolerant matching and serialization into Pydantic models for structured data access. ```python # Fuzzy lookup (requires [fuzzy] extra) name = CountryInfo("Singaproe").name() # Pydantic models (requires [pydantic] extra) model = CountryInfo("Singapore").model() print(model.name, model.population) ``` -------------------------------- ### Retrieve Country Metadata Source: https://github.com/porimol/countryinfo/blob/main/README.md Methods to retrieve specific metadata such as the official name, ISO codes, alternate spellings, and area measurements for a given country instance. ```python country = CountryInfo("Singapore") name = country.name() iso_codes = country.iso() alt_names = country.alt_spellings() area_km2 = country.area() ``` -------------------------------- ### Query and Filter Country Datasets Source: https://github.com/porimol/countryinfo/blob/main/README.md Utilities for retrieving lists of all countries or filtering them based on specific criteria like region, language, or currency. ```python from countryinfo import all_countries, filter_countries, CountryInfo # Get all countries countries = all_countries() # Filter countries asia = filter_countries(region="Asia") eurozone = filter_countries(currency="EUR") # Get raw data dictionary data = CountryInfo.all() ``` -------------------------------- ### Query Geographical and Administrative Details Source: https://github.com/porimol/countryinfo/blob/main/README.md Methods to access geographical data including capitals, coordinates, bordering countries, calling codes, currencies, and languages. ```python country = CountryInfo("Singapore") capital = country.capital() latlng = country.capital_latlng() borders = country.borders() currencies = country.currencies() languages = country.languages() calling_codes = country.calling_codes() ``` -------------------------------- ### Retrieve Country Metadata and Demographics Source: https://github.com/porimol/countryinfo/blob/main/README.md Methods to access specific country attributes such as languages, coordinates, population, and regional information using the CountryInfo class. ```python from countryinfo import CountryInfo country = CountryInfo("Singapore") print(country.languages()) print(country.latlng()) print(country.population()) print(country.provinces()) print(country.region()) print(country.subregion()) print(country.tld()) print(country.wiki()) print(country.google()) ``` -------------------------------- ### Advanced Country Queries Source: https://github.com/porimol/countryinfo/blob/main/README.md Advanced methods for retrieving neighboring countries as objects and fetching GeoJSON boundary data for mapping applications. ```python country = CountryInfo("France") # Get neighbors as objects for neighbor in country.neighbors(): print(neighbor.name(), neighbor.capital()) # Get GeoJSON boundary boundary = country.geo_json() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.