Skip to main content

Codacy Badge Coverage Status Top language Code size GitHub PyPI PyPI - Python Version PyPI - Implementation PyPI - Status

Flask-RestCountries

Flask-RestCountries provides a simple intergration for restcountries.com API with Flask Applications.

Installation

Use the package manager pip to install flask-restcountries.

pip install Flask-RestCountries

Usage

from flask import Flask
from flask_restcountries import CountriesAPI

app = Flask(__name__)


rapi = CountriesAPI(app)

if you are using blueprints

from flask_restcountries import CountriesAPI
rapi = CountriesAPI()

rapi.init_app(app)

Usage in App

@app.route('/get-all')
def get_all_countries():
    """all_countries is a list of Country Objects"""
    all_countries = rapi.get_all()
    return render_template("example.html", all_countries=all_countries)

Other Useful Methods

Get Countries By Calling Code string of a country. E.g. '254'.

countries=rapi.get_countries_by_calling_code("+254")

Get a Country By Alpha code string of a country. E.g. 'ke'.

countries=rapi.get_country_by_country_code("ke")

Get Countries By Capital string of a country. E.g. 'Nairobi'

countries=rapi.get_countries_by_capital("Nairobi")

Get Countries By Currency string of a country. E.g. 'KES'.

countries=rapi.get_countries_by_currency("KES")

Get Countries By Language string of a country. E.g. 'sw'.

countries=rapi.get_countries_by_language("sw")

Get Countries By Name string of a country. E.g. 'Kenya'.

countries=rapi.get_countries_by_name("Kenya")

Get Countries By Region string of a country. E.g. 'Africa'.

countries=rapi.get_countries_by_region("Africa")

Get Countries By Subregion string of a country. E.g. 'Eastern Africa'

countries=rapi.get_countries_by_subregion("Eastern Africa")

Response Filtering

To make the response return only afew selected fields, you can filter the response by passing a list of field to be returned in the filters keyword as a kwarg to the methods above. ie:-

countries=rapi.get_countries_by_calling_code("+254",filters=["name","currencies","capital"])

Attributes that can be passed to the filters keyword

- topLevelDomain
- alpha2Code
- alpha3Code
- currencies
- capital
- callingCodes
- altSpellings
- relevance
- region
- subregion
- translations
- population
- latlng
- demonym
- area
- gini
- timezones
- borders
- nativeName
- name
- numericCode
- languages
- flag
- regionalBlocs
- cioc

Attributes of the Country object returned per each request

- top_level_domain
- alpha2_code
- alpha3_code
- currencies
- capital
- calling_codes
- alt_spellings
- relevance
- region
- subregion
- translations
- population
- latlng
- demonym
- area
- gini
- timezones
- borders
- native_name
- name
- numeric_code
- languages
- flag
- regional_blocs
- cioc

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT

Metadata

Release files for Flask-RestCountries 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for Flask-RestCountries 1.2.0
File Size Uploaded
Flask-RestCountries-1.2.0.tar.gz 4.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for Flask-RestCountries 1.2.0
File Interpreter ABI Platform
Flask_RestCountries-1.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 8.5 kB

Release files / Flask-RestCountries-1.2.0.tar.gz

Download URL Flask-RestCountries-1.2.0.tar.gz
Size 4.1 kB
Tags Source
SHA-256 checksum
How to use checksums
a19cd9759670b1b97f1ef7f82d767a87af4f109509891f6d5e5cd82cd6715ae2
BLAKE2b-256 checksum
How to use checksums
ed501e460361afed2824371501b66e551ae182d0b5e6e567a8d0fcdef50e761a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

Release files / Flask_RestCountries-1.2.0-py3-none-any.whl

Download URL Flask_RestCountries-1.2.0-py3-none-any.whl
Size 4.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e7f8abda077a3217066072409f64301018fbbd763776290009b7aaa15d5988f5
BLAKE2b-256 checksum
How to use checksums
1484c99ffcfd364aed9c9a8806bc785e5fe0a17c3089ad3c62a10d324d9210ec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

Release history Release notifications | RSS feed

This release

1.2.0 This release

2 release files

1.1.3

1 release file

1.1.2

1 release file

1.1.1

1 release file

1.1.0

1 release file

1.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page