Python tool to obtain simple and practical geographic data.
Use this Python tool to obtain simple, practical geographic data.
Remember the days when you had to look up the names of various regions and countries on a physical globe or in a thick book?

All of this information is now accessible with a single click because to technological advancements, particularly the internet.
What if, though, you wanted to go a step further and discover crucial information about a nation, such its capital, location, or currency? You only need to use Python’s excellent Country Info module to complete the task quickly.
What Is the CountryInfo Module?
Porimol Chandro developed the Country Info module. It has functions to fetch a country’s capital city, geographical coordinates, timezone, area, population, and more.
To install this module, open your terminal and execute:

Additionally, you can obtain current weather information for any nation or region and add it to the information to improve your dataset: How to Fetch Live Weather Data Using Python (makeuseof.com)
How to Use the Module’s Functions
You can fetch information using the different functions of the CountryInfo module as follows.
1. Getting the Alternate Names or Spellings of a Country
You can fetch the alternate names or spellings of a country like so:

Start by importing the CountryInfo class from the countryinfo module. You can then create an instance of CountryInfo by passing it a string containing the name of a country.
You can call various API methods on the CountryInfo object you’ve created. For example, alt_spellings() returns a list of alternate names of the country.
The Python snippet for getting the alternate names of a country.
2. Getting the Capital and Its Geographic Coordinates
You can use capital() to get the capital city of any country.It returns a string representing the name of the capital:

Use the API method captial_latlng() to fetch the geographical coordinates of a country’s capital. This method returns a list containing two elements, each a floating point number:

3. Getting the Area of a Country, Its Provinces, and the Surrounding Border Countries
You can use the API method, area() to get the area of any country in square kilometers. Implement the code as:

You can get a list of provinces of a country using provinces().

You can fetch the names of bordering countries using the API method, borders(). Each element in the list is a country code in ISO-3 format, a three-character uppercase string.
4.Getting Currency, Population, and Timezones
Fetch the official currency format of a country using the API method, currencies()

5.Getting the Wikipedia URL of a Country
Wikipedia is one of the best sources of information for anything on the internet. You can fetch the Wikipedia page of a country using the API method, wiki(). Implement the code as:

Getting All the Available Information About a Country
You can fetch all the available information of a country using the API method, info(). It returns a dictionary of key/name values, which you can iterate over using a for loop:

Output:

Fetching Data From Websites
Even though this useful Python package gives you access to any country’s vital facts, getting clean data is a difficult effort. Knowing how to scrape data from any page on the internet would be helpful. After that, you can examine and use the data to your applications.
You can install Python’s potent BeautifulSoup module to perform web scraping and save hours of labor.