### GET /api/all - Python example Source: https://github.com/amckenna41/iso3166-2/blob/main/API.md Python example using requests to fetch all subdivision data from the /api/all endpoint. ```python import requests request_url = "https://iso3166-2-api.vercel.app/api/all" all_request = requests.get(request_url) all_request.json() ``` -------------------------------- ### GET /api/all - JavaScript example Source: https://github.com/amckenna41/iso3166-2/blob/main/API.md JavaScript example using fetch to retrieve all subdivision data from the /api/all endpoint. ```javascript function getData() { const response = await fetch('https://iso3166-2-api.vercel.app/api/all') const data = await response.json() } // Begin accessing JSON data here var data = JSON.parse(this.response) ``` -------------------------------- ### GET /api/alpha/{alpha3} - Python example Source: https://github.com/amckenna41/iso3166-2/blob/main/API.md Python example using requests to fetch subdivision data for a country by alpha-3 code. Change input_alpha3 to 'HRV' for Croatia. ```python import requests base_url = "https://iso3166-2-api.vercel.app/api/alpha/" input_alpha3 = "CZE" #HRV request_url = f'{base_url}{input_alpha3}' all_request = requests.get(request_url) all_request.json() ``` -------------------------------- ### GET /api/alpha/{alpha2} - Python example Source: https://github.com/amckenna41/iso3166-2/blob/main/API.md Python example using requests to fetch subdivision data for a country by alpha-2 code. Change input_alpha2 to 'DE' for Germany. ```python import requests base_url = "https://iso3166-2-api.vercel.app/api/alpha/" input_alpha2 = "FR" #DE request_url = f'{base_url}{input_alpha2}' all_request = requests.get(request_url) all_request.json() ``` -------------------------------- ### GET /api/alpha/{alpha2} - JavaScript example Source: https://github.com/amckenna41/iso3166-2/blob/main/API.md JavaScript example using fetch to retrieve subdivision data for a country by alpha-2 code. Change input_alpha2 to 'DE' for Germany. ```javascript let input_alpha2 = "FR"; //DE function getData() { const response = await fetch(`https://iso3166-2-api.vercel.app/api/alpha/${input_alpha2}`); const data = await response.json() } // Begin accessing JSON data here var data = JSON.parse(this.response) ``` -------------------------------- ### Install test dependencies Source: https://github.com/amckenna41/iso3166-2/blob/main/tests/README.md Install the required packages for running the tests, as listed in tests/requirements.txt. ```bash pip install -r tests/requirements.txt ``` -------------------------------- ### Install Sphinx Source: https://github.com/amckenna41/iso3166-2/blob/main/docs/README.md Installs the Sphinx package required to build the documentation. ```bash pip install sphinx ``` -------------------------------- ### Install iso3166-2 with pip Source: https://github.com/amckenna41/iso3166-2/blob/main/README.md Install or upgrade the latest version of iso3166-2 from PyPi. Use the --upgrade flag to ensure the newest release is installed. ```bash pip install iso3166-2 --upgrade ``` -------------------------------- ### Install iso3166-2 via pip Source: https://github.com/amckenna41/iso3166-2/blob/main/docs/usage.rst Install the iso3166-2 package using pip. Run this command in your terminal before using the library. ```console pip install iso3166-2 ``` -------------------------------- ### GET /api/all - HTTP response Source: https://github.com/amckenna41/iso3166-2/blob/main/API.md Example HTTP response for the /api/all endpoint, showing a 200 status and JSON body with country codes. ```http HTTP/2 200 content-type: application/json date: Wed, 20 Dec 2024 17:29:39 GMT server: Vercel content-length: 837958 {"AD":..., "AE":...} ``` -------------------------------- ### CLI Command Errors - Use --help Source: https://github.com/amckenna41/iso3166-2/blob/main/docs/troubleshooting.rst Use --help with any command to see usage. If you receive an import error in a local clone, run commands from the repository root or install editable mode with pip install -e . ```console iso3166-2 --help iso3166-2 search --help iso3166-2 reverse --help ``` ```console pip install -e . ``` -------------------------------- ### GET /api/alpha/CZE - HTTP response Source: https://github.com/amckenna41/iso3166-2/blob/main/API.md Example HTTP response for the /api/alpha/CZE endpoint, showing a 200 status and JSON body with Czech subdivisions. ```http HTTP/2 200 content-type: application/json date: Wed, 20 Dec 2024 17:42:24 GMT server: Vercel content-length: 14266 {"CZ":{"CZ-10":{"..."}}} ``` -------------------------------- ### Extract subdivision codes via subscripting Source: https://github.com/amckenna41/iso3166-2/blob/main/docs/usage.rst Shows how to get subdivision codes by subscripting the Subdivisions object with a country code, using 'AL' and 'ET' as examples. ```python iso["AL"].subdivision_names() iso["ET"].subdivision_names() ``` -------------------------------- ### GET /api/all Source: https://github.com/amckenna41/iso3166-2/blob/main/API.md Retrieves all ISO 3166 subdivision data for all countries. ```APIDOC ## GET /api/all ### Description Get all of the ISO 3166 subdivision data for all countries. ### Method GET ### Endpoint https://iso3166-2-api.vercel.app/api/all ### Response #### Success Response (200) Returns all ISO 3166 subdivision data for all countries. ``` -------------------------------- ### Get total number of subdivisions with len() Source: https://github.com/amckenna41/iso3166-2/blob/main/docs/usage.rst Create a Subdivisions instance and use the built-in len() function to get the total number of subdivision objects. The example notes the count is 5,046. ```python from iso3166_2 import * #create instance of Subdivisions class iso = Subdivisions() #get total number of subdivision objects via len() - 5,046 len(iso) ``` -------------------------------- ### Extract subdivision names via subscripting Source: https://github.com/amckenna41/iso3166-2/blob/main/docs/usage.rst Shows how to get subdivision names by subscripting the Subdivisions object with a country code, using 'BA' and 'MI' as examples. ```python iso["BA"].subdivision_names() iso["MI"].subdivision_names() ``` -------------------------------- ### Python example for /api/all endpoint with filter Source: https://github.com/amckenna41/iso3166-2/blob/main/API.md Python script using requests to fetch all ISO 3166-2 data with a filter for name and localOtherName attributes. ```python import requests request_url = "https://iso3166-2-api.vercel.app/api/all" all_request = requests.get(request_url, params={"filter": "name, localOtherName"}) all_request.json() ``` -------------------------------- ### Get dataset size in MB with iso.__sizeof__() Source: https://github.com/amckenna41/iso3166-2/blob/main/iso3166_2/README.md Returns the size of the dataset in megabytes. ```python iso.__sizeof__() ``` -------------------------------- ### Get subdivision data by subdivision code Source: https://github.com/amckenna41/iso3166-2/blob/main/iso3166_2/README.md Access a specific subdivision's data using its subdivision code (e.g., 'CA-AB'). The example shows various country and subdivision code combinations. ```python iso["CA"]['CA-AB'] #Alberta subdivision iso["DK"]['DK-81'] #Nordjylland subdivision iso["EST"]['EE-899'] #Viljandi subdivision iso["FJI"]['FJ-03'] #Cakaudrove subdivision iso["PE"]["PE-LAL"] #La Libertad subdivision iso["604"]['PE-AMA'] #Amarumayu subdivision ``` -------------------------------- ### List all subdivision codes per country with Python Requests Source: https://github.com/amckenna41/iso3166-2/blob/main/docs/api.rst Use the /list_subdivisions endpoint to get all subdivision codes for a country by appending its ISO 3166-1 code. The example shows fetching data for Germany, Oman, and the US, both for all countries and specific ones. ```python import requests base_url = "https://iso3166-2-api.vercel.app/api/list_subdivisions" all_data = requests.get(base_url) all_data["DE"] #subdivision codes for Germany all_data["OM"] #subdivision data for Oman all_data["US"] #subdivision data for US #get specific subdivision list via country code base_url = "https://iso3166-2-api.vercel.app/api/list_subdivisions/DE" all_data = requests.get(base_url) base_url = "https://iso3166-2-api.vercel.app/api/list_subdivisions/OM" all_data = requests.get(base_url) base_url = "https://iso3166-2-api.vercel.app/api/list_subdivisions/US" all_data = requests.get(base_url) ``` -------------------------------- ### GET /api/alpha/FR - HTTP response Source: https://github.com/amckenna41/iso3166-2/blob/main/API.md Example HTTP response for the /api/alpha/FR endpoint, showing a 200 status and JSON body with French subdivisions. ```http HTTP/2 200 content-type: application/json date: Wed, 20 Dec 2024 17:30:27 GMT server: Vercel content-length: 26298 {"FR":{"FR-01":{...}}} ``` -------------------------------- ### JavaScript example for /api/all endpoint with filter Source: https://github.com/amckenna41/iso3166-2/blob/main/API.md JavaScript function using fetch to retrieve all ISO 3166-2 data with a filter for name and localOtherName attributes. ```javascript function getData() { const response = await fetch('https://iso3166-2-api.vercel.app/api/all?filter=name,localOtherName') const data = await response.json() } // Begin accessing JSON data here var data = JSON.parse(this.response) ``` -------------------------------- ### GET /api/alpha/DE - HTTP response Source: https://github.com/amckenna41/iso3166-2/blob/main/API.md Example HTTP response for the /api/alpha/DE endpoint, showing a 200 status and JSON body with German subdivisions. ```http HTTP/2 200 content-type: application/json date: Wed, 20 Dec 2024 17:31:19 GMT server: Vercel content-length: 3053 {"DE":{"DE-BB":{...}}} ``` -------------------------------- ### Get subdivision data by country name (Python Requests) Source: https://github.com/amckenna41/iso3166-2/blob/main/docs/api.rst Fetches JSON data for all subdivisions of a country using its English name. The example uses Tajikistan, with Seychelles and Uganda commented out. The response is a JSON object keyed by country code. ```python import requests base_url = "https://iso3166-2-api.vercel.app/api/" input_country_name = "Tajikistan" #Seychelles, Uganda all_data = requests.get(f'{base_url}/country_name/{input_country_name}').json() all_data["TJ"] #subdivision data for Tajikistan #all_data["SC"] #subdivision data for Seychelles #all_data["UG"] #subdivision data for Uganda ``` -------------------------------- ### GET /api/alpha/HRV - HTTP response Source: https://github.com/amckenna41/iso3166-2/blob/main/API.md Example HTTP response for the /api/alpha/HRV endpoint, showing a 200 status and JSON body with Croatian subdivisions. ```http HTTP/2 200 content-type: application/json date: Wed, 20 Dec 2024 17:46:12 GMT server: Vercel content-length: 5456 {"HR":{"HR-01":{"..."}}} ``` -------------------------------- ### Check for updates with iso.check_for_updates Source: https://github.com/amckenna41/iso3166-2/blob/main/iso3166_2/README.md Compares the installed subdivision data with the latest version on the repository and outputs any differences. ```python ''' Compare the subdivision data in the current installed version of the iso3166-2 software with the most up-to-date and accurate version on the repository. If there are any difference between these objects, they will be output. ''' iso.check_for_updates() ``` -------------------------------- ### Get subdivision data by subdivision code (Python Requests) Source: https://github.com/amckenna41/iso3166-2/blob/main/docs/api.rst Fetches JSON data for one or more subdivisions using their ISO 3166-2 codes. The example uses LV-007, with PA-3 and ZA-NC commented out. The response is a JSON object keyed by subdivision code. ```python import requests base_url = "https://iso3166-2-api.vercel.app/api/" input_subdivision = "LV-007" #PA-3, ZA-NC all_data = requests.get(f'{base_url}/subdivision/{input_subdivision}').json() all_data["LV-007"] #data for LV-007 subdivision #all_data["PA-3"] #data for PA-3 subdivision #all_data["ZA-NC"] #data for ZA-NC subdivision ``` -------------------------------- ### Extract all subdivision names for all countries Source: https://github.com/amckenna41/iso3166-2/blob/main/docs/usage.rst Creates a Subdivisions instance and calls subdivision_names() with no arguments to get all subdivision names for all countries. ```python from iso3166_2 import * #crete instance of Subdivisions class iso = Subdivisions() iso.subdivision_names() ``` -------------------------------- ### Export subdivision data to a pandas DataFrame Source: https://github.com/amckenna41/iso3166-2/blob/main/docs/usage.rst Creates a Subdivisions instance and uses to_dataframe() to get a flat DataFrame of all subdivisions, or for a specific country (e.g., 'CA'). The resulting DataFrame can be exported to CSV. Requires the optional pandas dependency, installable via 'pip install iso3166-2[export]'. ```python from iso3166_2 import * #create instance of Subdivisions class iso = Subdivisions() #get a DataFrame of all subdivisions for all countries df = iso.to_dataframe() #get a DataFrame of just the Canadian subdivisions ca_df = Subdivisions("CA").to_dataframe() #export to CSV df.to_csv("iso3166_2.csv", index=False) ``` -------------------------------- ### GET /api/all Source: https://github.com/amckenna41/iso3166-2/blob/main/API.md Retrieves all ISO 3166-2 subdivision data for all countries. Returns a JSON object keyed by country code. ```APIDOC ## GET /api/all ### Description Retrieves all ISO 3166-2 subdivision data for all countries. ### Method GET ### Endpoint /api/all ### Parameters #### Query Parameters - **filter** (string) - Optional - Comma-separated list of attributes to include in the output. Default: all attributes. ### Request Example ``` curl -i https://iso3166-2-api.vercel.app/api/all ``` ### Response #### Success Response (200) - **content-type**: application/json - **body**: JSON object with country codes as keys and subdivision data as values. #### Response Example ``` {"AD":..., "AE":...} ``` ``` -------------------------------- ### GET /api/all Source: https://github.com/amckenna41/iso3166-2/blob/main/README.md Retrieves all ISO 3166-2 subdivision data, with optional filter parameter. ```APIDOC ## [GET] /api/all ### Description Retrieves all ISO 3166-2 subdivision data, with optional filter parameter. ### Method GET ### Endpoint /api/all ### Parameters #### Query Parameters - **filter** (string) - Optional - List of default supported attributes to include in the output. By default all attributes are returned. ### Request Example /api/all?filter=latLng,flag ### Response #### Success Response (200) - **latLng** (string) - Latitude and longitude of the country. - **flag** (string) - Flag of the country. ``` -------------------------------- ### Python example for /api/country_name endpoint Source: https://github.com/amckenna41/iso3166-2/blob/main/API.md Python script using requests to fetch ISO 3166-2 data for a country name. Change the input_name variable to 'Seychelles' or 'Uganda' for other countries. ```python import requests base_url = "https://iso3166-2-api.vercel.app/api/country_name/" input_name = "Tajikistan" #Seychelles, Uganda request_url = f'{base_ur}{input_name}' all_request = requests.get(request_url) all_request.json() ``` -------------------------------- ### Extract all subdivision codes for all countries Source: https://github.com/amckenna41/iso3166-2/blob/main/docs/usage.rst Creates a Subdivisions instance and calls subdivision_codes() with no arguments to get all subdivision codes for all countries. ```python from iso3166_2 import * #crete instance of Subdivisions class iso = Subdivisions() iso.subdivision_codes() ``` -------------------------------- ### GET /api/all - curl request Source: https://github.com/amckenna41/iso3166-2/blob/main/API.md Retrieves all ISO 3166-2 subdivision data for all countries. Returns a JSON object keyed by country code. ```bash curl -i https://iso3166-2-api.vercel.app/api/all ``` -------------------------------- ### JavaScript example for /api/country_name endpoint Source: https://github.com/amckenna41/iso3166-2/blob/main/API.md JavaScript function using fetch to retrieve ISO 3166-2 data for a country name. Change input_name to 'Seychelles' or 'Uganda' for other countries. ```javascript let input_name = "Tajikistan"; //Seychelles, Uganda function getData() { const response = await fetch(`https://iso3166-2-api.vercel.app/api/country_name/${input_name}`); const data = await response.json() } // Begin accessing JSON data here var data = JSON.parse(this.response) ``` -------------------------------- ### GET /api/alpha/{input_alpha} Source: https://github.com/amckenna41/iso3166-2/blob/main/docs/api.rst Returns subdivision data for a country specified by its ISO 3166-1 alpha-2, alpha-3, or numeric code. ```APIDOC ## GET /api/alpha/{input_alpha} ### Description Returns subdivision data for a country specified by its ISO 3166-1 alpha-2, alpha-3, or numeric code. ### Method GET ### Endpoint https://iso3166-2-api.vercel.app/api/alpha/{input_alpha} ### Parameters #### Path Parameters - **input_alpha** (string) - Required - The alpha-2, alpha-3, or numeric ISO 3166-1 country code. ### Response #### Success Response (200) - **data** (object) - Contains subdivision data for the specified country. #### Response Example { "data": {} } ``` -------------------------------- ### GET /api/country_name/{input_country_name} Source: https://github.com/amckenna41/iso3166-2/blob/main/docs/api.rst Returns subdivision data for a country specified by its name. ```APIDOC ## GET /api/country_name/{input_country_name} ### Description Returns subdivision data for a country specified by its name. ### Method GET ### Endpoint https://iso3166-2-api.vercel.app/api/country_name/{input_country_name} ### Parameters #### Path Parameters - **input_country_name** (string) - Required - The name of the country. ### Response #### Success Response (200) - **data** (object) - Contains subdivision data for the specified country. #### Response Example { "data": {} } ``` -------------------------------- ### Python example for /api/list_subdivisions endpoint Source: https://github.com/amckenna41/iso3166-2/blob/main/API.md Python script using requests to fetch all ISO 3166-2 subdivision codes. Uncomment the second request_url line to fetch for a specific country code like LK. ```python import requests request_url = "https://iso3166-2-api.vercel.app/api/list_subdivisions" #request_url = "https://iso3166-2-api.vercel.app/api/list_subdivisions/LK" all_request = requests.get(request_url) all_request.json() ``` -------------------------------- ### Get all subdivision data with curl Source: https://github.com/amckenna41/iso3166-2/blob/main/docs/api.rst Uses curl to request the /api/all endpoint, returning all subdivision data for all countries. ```default $ curl -i https://iso3166-2-api.vercel.app/api/all ``` -------------------------------- ### GET /api/alpha/CZE - curl request Source: https://github.com/amckenna41/iso3166-2/blob/main/API.md Retrieves subdivision data for Czechia using its alpha-3 code CZE. ```bash curl -i https://iso3166-2-api.vercel.app/api/alpha/CZE ``` -------------------------------- ### Query String Parameters Source: https://github.com/amckenna41/iso3166-2/blob/main/docs/api.rst Describes the available query string parameters that can be appended to GET requests to customize API responses. ```APIDOC ## Query String Parameters ### Description These parameters can be appended to GET requests to customize the API response. ### Parameters #### Query Parameters - **likeness** (integer) - Optional - A value between 1 and 100 that controls the similarity percentage required for search terms to match subdivision names. Higher values return more exact matches, lower values return more matches. Default is 100. Used with /api/search and /api/country_name endpoints. - **filterAttributes** (string) - Optional - A comma-separated list of attributes to include in the output. Can be used with any endpoint. Example: /api/alpha/AL,BA,CD?filterAttributes=name,type,parentCode - **excludeMatchScore** (boolean) - Optional - When set to 1 (True), excludes the matchScore attribute from search results and sorts results by country code. Default is 0. Used with /api/search endpoint. - **limit** (integer) - Optional - Limits the number of countries returned. Only available on /api/all endpoint. Default is None. ### Usage Examples - /api/search/Paris?likeness=50 - /api/search/Louisianna?likeness=90 - /api/alpha/AL,BA,CD?filterAttributes=name,type,parentCode - /api/subdivision/LV-112?filterAttributes=localOtherName,flag,history - /api/search/Bernardo O’higgins?excludeMatchScore=1 - /api/search/New York?excludeMatchScore=1 - /api/all?limit=10 - /api/all?limit=50 ``` -------------------------------- ### JavaScript example for /api/list_subdivisions endpoint Source: https://github.com/amckenna41/iso3166-2/blob/main/API.md JavaScript function using fetch to retrieve all ISO 3166-2 subdivision codes. Uncomment the second fetch line to fetch for a specific country code like LK. ```javascript function getData() { const response = await fetch(`https://iso3166-2-api.vercel.app/api/list_subdivisions`); // await fetch(`https://iso3166-2-api.vercel.app/api/list_subdivisions/LK`); const data = await response.json() } // Begin accessing JSON data here var data = JSON.parse(this.response) ``` -------------------------------- ### GET /api/subdivision/{input_subdivision} Source: https://github.com/amckenna41/iso3166-2/blob/main/docs/api.rst Returns data for a specific ISO 3166-2 subdivision identified by its subdivision code or name. ```APIDOC ## GET /api/subdivision/{input_subdivision} ### Description Returns data for a specific ISO 3166-2 subdivision identified by its subdivision code or name. ### Method GET ### Endpoint https://iso3166-2-api.vercel.app/api/subdivision/{input_subdivision} ### Parameters #### Path Parameters - **input_subdivision** (string) - Required - The ISO 3166-2 subdivision code or name. ### Response #### Success Response (200) - **data** (object) - Contains data for the specified subdivision. #### Response Example { "data": {} } ``` -------------------------------- ### GET /api/list_subdivisions/{input_alpha} Source: https://github.com/amckenna41/iso3166-2/blob/main/docs/api.rst Lists all subdivisions for a country specified by its ISO 3166-1 alpha code. ```APIDOC ## GET /api/list_subdivisions/{input_alpha} ### Description Lists all subdivisions for a country specified by its ISO 3166-1 alpha code. ### Method GET ### Endpoint https://iso3166-2-api.vercel.app/api/list_subdivisions/{input_alpha} ### Parameters #### Path Parameters - **input_alpha** (string) - Required - The alpha-2, alpha-3, or numeric ISO 3166-1 country code. ### Response #### Success Response (200) - **data** (object) - Contains a list of subdivisions for the specified country. #### Response Example { "data": {} } ``` -------------------------------- ### GET /api/list_subdivisions/{country_code} Source: https://github.com/amckenna41/iso3166-2/blob/main/docs/api.rst Return a list of all ISO 3166-2 subdivision codes for a specific country by appending its ISO 3166-1 country code. ```APIDOC ## GET /api/list_subdivisions/{country_code} ### Description Return a list of all ISO 3166-2 subdivision codes for a specific country by appending its ISO 3166-1 country code. ### Method GET ### Endpoint https://iso3166-2-api.vercel.app/api/list_subdivisions/{country_code} ### Parameters #### Path Parameters - **country_code** (string) - Required - ISO 3166-1 country code (e.g., DE, OM, US). ### Request Example ``` https://iso3166-2-api.vercel.app/api/list_subdivisions/DE ``` ### Response #### Success Response (200) - **all_data** (object) - JSON object with keys as ISO 3166-1 country codes and values as lists of subdivision codes. #### Response Example ```json { "DE": ["DE-BW", "DE-BY", ...] } ``` ``` -------------------------------- ### Get all subdivision data for all countries Source: https://github.com/amckenna41/iso3166-2/blob/main/docs/usage.rst Create a Subdivisions instance and access the 'all' attribute to retrieve subdivision data for all countries. Then access individual countries by their ISO 3166-1 alpha-2, alpha-3, or numeric codes. ```python from iso3166_2 import * #crete instance of Subdivisions class iso = Subdivisions() all_data = iso.all all_data["LU"] #all subdivision data for Luxembourg all_data["PW"] #all subdivision data for Palau all_data["TUV"] #all subdivision data for Tuvalu all_data["UKR"] #all subdivision data for Ukraine all_data["876"] #all subdivision data for Wallis & Futuna all_data["716"] #all subdivision data for Zimbabwe ``` -------------------------------- ### GET /api/search/{input_search} Source: https://github.com/amckenna41/iso3166-2/blob/main/docs/api.rst Performs a free-text search across ISO 3166-2 data. ```APIDOC ## GET /api/search/{input_search} ### Description Performs a free-text search across ISO 3166-2 data. ### Method GET ### Endpoint https://iso3166-2-api.vercel.app/api/search/{input_search} ### Parameters #### Path Parameters - **input_search** (string) - Required - The search query. ### Response #### Success Response (200) - **data** (object) - Contains search results. #### Response Example { "data": {} } ``` -------------------------------- ### Get total number of subdivisions with len(iso) Source: https://github.com/amckenna41/iso3166-2/blob/main/iso3166_2/README.md Returns the total number of subdivisions in the iso3166-2 object. ```python len(iso) ``` -------------------------------- ### GET /api/alpha/HRV - curl request Source: https://github.com/amckenna41/iso3166-2/blob/main/API.md Retrieves subdivision data for Croatia using its alpha-3 code HRV. ```bash curl -i https://iso3166-2-api.vercel.app/api/alpha/HRV ``` -------------------------------- ### check_for_updates Source: https://github.com/amckenna41/iso3166-2/blob/main/iso3166_2/README.md Compares the subdivision data in the current installed version of the iso3166-2 software with the most up-to-date version on the repository. Outputs any differences between the objects. ```APIDOC ## check_for_updates ### Description Compares the subdivision data in the current installed version of the iso3166-2 software with the most up-to-date version on the repository. Outputs any differences between the objects. ### Method check_for_updates ### Parameters None ### Request Example ```python iso.check_for_updates() ``` ### Response Outputs differences between the current and repository data. ``` -------------------------------- ### Run sphinx-quickstart Source: https://github.com/amckenna41/iso3166-2/blob/main/docs/README.md Runs sphinx-quickstart in the /docs directory to create the documentation template. ```bash cd /docs && sphinx-quickstart ``` -------------------------------- ### Check for the latest Subdivision data Source: https://github.com/amckenna41/iso3166-2/blob/main/docs/usage.rst Creates a Subdivisions instance and calls check_for_updates() to compare the installed data with the latest data from the iso3166-2 GitHub repo. Any changes found are output, indicating that the package should be upgraded or reinstalled. ```python from iso3166_2 import * #create instance of Subdivisions class iso = Subdivisions() #compare latest subdivision data from repo iso.check_for_updates() ``` -------------------------------- ### Build HTML documentation Source: https://github.com/amckenna41/iso3166-2/blob/main/docs/README.md Builds the documentation using the make command in the /docs folder. ```bash make html ``` -------------------------------- ### GET /api/list_subdivisions Source: https://github.com/amckenna41/iso3166-2/blob/main/API.md Retrieves a list of all subdivision codes for all countries, or for a subset of countries via their ISO 3166-1 country code. ```APIDOC ## GET /api/list_subdivisions ### Description Get list of all the subdivision codes for all countries. You can also get the list of subdivisions from a subset of countries via their ISO 3166-1 country code. ### Method GET ### Endpoint https://iso3166-2-api.vercel.app/api/list_subdivisions ### Parameters #### Query Parameters - **country_code** (string) - Optional - ISO 3166-1 country code to filter subdivisions by. ### Response #### Success Response (200) Returns a list of subdivision codes for all countries or for the specified country. ``` -------------------------------- ### GET /api/all Source: https://github.com/amckenna41/iso3166-2/blob/main/API.md Retrieves all ISO 3166-2 subdivision codes for all countries, with optional filtering to return only specific attributes. The response is a JSON object with country codes as keys and subdivision data as values. ```APIDOC ## GET /api/all ### Description Retrieves all ISO 3166-2 subdivision codes for all countries, with optional filtering to return only specific attributes. ### Method GET ### Endpoint https://iso3166-2-api.vercel.app/api/all ### Parameters #### Query Parameters - **filter** (string) - Optional - Comma-separated list of attributes to include in the response (e.g., name, localOtherName). ### Request Example ``` curl -i "https://iso3166-2-api.vercel.app/api/all?filter=name,localOtherName" ``` ### Response #### Success Response (200) - **content-type**: application/json - **body**: JSON object with country codes as keys and subdivision data as values. #### Response Example ``` {"AD":..., "AE":...} ``` ``` -------------------------------- ### Get subdivision data by country name (curl) Source: https://github.com/amckenna41/iso3166-2/blob/main/docs/api.rst Uses curl to fetch subdivision data for Tajikistan, Seychelles, and Uganda. Each command returns the JSON response for the specified country name. ```default $ curl -i https://iso3166-2-api.vercel.app/api/country_name/Tajikistan $ curl -i https://iso3166-2-api.vercel.app/api/country_name/Seychelles $ curl -i https://iso3166-2-api.vercel.app/api/country_name/Uganda ``` -------------------------------- ### GET /api/country_name/Uganda - curl request and response Source: https://github.com/amckenna41/iso3166-2/blob/main/API.md Retrieves ISO 3166-2 subdivision codes for Uganda. The response is a JSON object with the country code as key and subdivision codes as values. ```bash curl -i https://iso3166-2-api.vercel.app/api/country_name/Uganda ``` ```http HTTP/2 200 content-type: application/json date: Sat, 23 Dec 2024 14:17:39 GMT server: Vercel content-length: 14965 {"UG":{"UG-101":{...}}} ``` -------------------------------- ### Run main.py to download all ISO 3166-2 subdivision data Source: https://github.com/amckenna41/iso3166-2/blob/main/scripts/README.md Run from the main repo directory in a terminal or command line. The script takes around 1 hour and 20 minutes to complete. ```bash python main.py ``` -------------------------------- ### GET /api/subdivision/{input_subdivision} Source: https://github.com/amckenna41/iso3166-2/blob/main/API.md Retrieves ISO 3166 subdivision data for one or more ISO 3166-2 subdivision codes. Accepts comma-separated lists of codes from same or different countries. ```APIDOC ## GET /api/subdivision/{input_subdivision} ### Description Get all of the ISO 3166 subdivision data for 1 or more ISO 3166-2 subdivision codes. You can also input a comma separated list of subdivision codes from the same and or different countries and the data for each will be returned. If the input subdivision code is not in the correct format then an error will be raised. Similarly if an invalid subdivision code that doesn't exist is input then an error will be raised. ### Method GET ### Endpoint https://iso3166-2-api.vercel.app/api/subdivision/{input_subdivision} ### Parameters #### Path Parameters - **input_subdivision** (string) - Required - ISO 3166-2 subdivision code(s). Comma-separated lists are allowed. ### Request Example GET /api/subdivision/GB-ABD GET /api/subdivision/IE-MO,FI-17,RO-AG ### Response #### Success Response (200) Returns ISO 3166 subdivision data for the specified subdivision codes. #### Error Response Returns an error if the subdivision code format is invalid or the code does not exist. ``` -------------------------------- ### Search for multiple subdivisions by name (curl) Source: https://github.com/amckenna41/iso3166-2/blob/main/docs/api.rst Uses curl to search for subdivisions by name. The example shows separate requests for 'Saarland', 'Brokopondo', and 'Delaware', and a combined request for all three. ```default $ curl -i https://iso3166-2-api.vercel.app/api/search/Saarland $ curl -i https://iso3166-2-api.vercel.app/api/search/Brokopondo $ curl -i https://iso3166-2-api.vercel.app/api/search/Delaware $ curl -i https://iso3166-2-api.vercel.app/api/search/Saarland,Brokopondo,Delaware ``` -------------------------------- ### Open generated index.html Source: https://github.com/amckenna41/iso3166-2/blob/main/docs/README.md Opens the generated index.html file in the docs/_build/html folder. ```bash open _build/html/index.html ``` -------------------------------- ### Get subdivision names for one or more countries Source: https://github.com/amckenna41/iso3166-2/blob/main/iso3166_2/README.md Returns a key-value pair of country code and subdivision names. Requires creating a Subdivisions instance first. Can be called on the instance or after subscripting a country code. ```python #create instance of Subdivisions class iso = Subdivisions() #get list of all subdivision names - returns a key value pair of country code and subdivision names: {"AD": [...], "AE": [...], "AF": [...]} iso.subdivision_names() #get list of all subdivision names for PL, RW & ST iso.subdivision_names("PL,RW,ST") #you can also call the subdivision_names() function after subscripting a country code iso["AL"].subdivision_names() ``` -------------------------------- ### GET /api/alpha/{input_alpha} Source: https://github.com/amckenna41/iso3166-2/blob/main/API.md Retrieves ISO 3166 subdivision data for one or more ISO 3166-1 alpha-2, alpha-3, or numeric country codes. Accepts comma-separated lists of codes. ```APIDOC ## GET /api/alpha/{input_alpha} ### Description Get all of the ISO 3166 subdivision data for 1 or more inputted ISO 3166-1 alpha-2, alpha-3 or numeric country codes. A comma separated list of multiple alpha codes can also be input. If an invalid country code is input then an error will be returned. ### Method GET ### Endpoint https://iso3166-2-api.vercel.app/api/alpha/{input_alpha} ### Parameters #### Path Parameters - **input_alpha** (string) - Required - ISO 3166-1 alpha-2, alpha-3, or numeric country code(s). Comma-separated lists are allowed. ### Request Example GET /api/alpha/FR,DE,HU,ID,MA GET /api/alpha/FRA,DEU,HUN,IDN,MAR GET /api/alpha/428,504,638 ### Response #### Success Response (200) Returns ISO 3166 subdivision data for the specified country codes. #### Error Response Returns an error if an invalid country code is input. ``` -------------------------------- ### Create /docs directory Source: https://github.com/amckenna41/iso3166-2/blob/main/docs/README.md Creates a /docs directory inside the iso3166-2 package. ```bash mkdir /docs ``` -------------------------------- ### Run all unit tests Source: https://github.com/amckenna41/iso3166-2/blob/main/tests/README.md Run all unit tests from the main iso3166-2 directory. The -v flag produces more verbose output. ```bash python -m unittest discover tests -v #-v produces a more verbose and useful output ``` -------------------------------- ### Search subdivision by name Treviso (curl and response) Source: https://github.com/amckenna41/iso3166-2/blob/main/API.md Curl request to GET /api/search/Treviso. The response is HTTP/2 200 with JSON body containing subdivision data for Italy (IT-TV). ```bash curl -i https://iso3166-2-api.vercel.app/api/search/Treviso ``` ```http HTTP/2 200 content-type: application/json date: Mon, 29 Jan 2025 13:02:10 GMT server: Vercel content-length: 215 {"IT-TV":{"flag":"}} ``` -------------------------------- ### Search subdivision by name Musandam (curl and response) Source: https://github.com/amckenna41/iso3166-2/blob/main/API.md Curl request to GET /api/search/Musandam. The response is HTTP/2 200 with JSON body containing subdivision data for Oman (OM-MU). ```bash curl -i https://iso3166-2-api.vercel.app/api/search/Musandam ``` ```http HTTP/2 200 content-type: application/json date: Mon, 29 Jan 2025 13:11:09 GMT server: Vercel content-length: 132 {"OM-MU":{"flag":}} ``` -------------------------------- ### GET /api/alpha Source: https://github.com/amckenna41/iso3166-2/blob/main/docs/api.rst Retrieves ISO 3166 subdivision data for one or more ISO 3166-1 alpha-2, alpha-3, or numeric country codes. Accepts comma-separated codes. Returns an error for invalid codes. ```APIDOC ## GET /api/alpha ### Description Retrieves ISO 3166 subdivision data for one or more ISO 3166-1 alpha-2, alpha-3, or numeric country codes. Accepts comma-separated codes. Returns an error for invalid codes. ### Method GET ### Endpoint /api/alpha/{codes} ### Parameters #### Path Parameters - **codes** (string) - Required - Comma-separated list of ISO 3166-1 alpha-2, alpha-3, or numeric country codes. Example: `FR,DE,HU,ID,MA`, `FRA,DEU,HUN,IDN,MAR`, `428,504,638`. ### Request Example GET /api/alpha/FR,DE,HU,ID,MA ### Response #### Success Response (200) Returns subdivision data for each provided country code. #### Error Response Returns an error if an invalid country code is input. ``` -------------------------------- ### GET /api/subdivision Source: https://github.com/amckenna41/iso3166-2/blob/main/docs/api.rst Retrieves ISO 3166 subdivision data for one or more ISO 3166-2 subdivision codes. Accepts comma-separated codes from same or different countries. Returns errors for invalid format or non-existent codes. ```APIDOC ## GET /api/subdivision ### Description Retrieves ISO 3166 subdivision data for one or more ISO 3166-2 subdivision codes. Accepts comma-separated codes from same or different countries. Returns errors for invalid format or non-existent codes. ### Method GET ### Endpoint /api/subdivision/{codes} ### Parameters #### Path Parameters - **codes** (string) - Required - Comma-separated list of ISO 3166-2 subdivision codes. Example: `GB-ABD`, `IE-MO,FI-17,RO-AG`. ### Request Example GET /api/subdivision/GB-ABD ### Response #### Success Response (200) Returns subdivision data for each provided subdivision code. #### Error Response Returns an error if the input subdivision code is not in the correct format or does not exist. ``` -------------------------------- ### Run a specific unit test module Source: https://github.com/amckenna41/iso3166-2/blob/main/tests/README.md Run a specific unit test module (e.g., test_iso3166_2) from the main iso3166-2 directory. The -v flag produces more verbose output. ```bash python -m unittest discover tests.test_iso3166_2 -v #-v produces a more verbose and useful output ``` -------------------------------- ### Search subdivision geography with Python Requests Source: https://github.com/amckenna41/iso3166-2/blob/main/docs/api.rst Use the /search_geo endpoint to search for subdivisions by name or code and get geographic attributes. The example searches for 'Saarland' and 'US-CA', returning data for DE-SL and US-CA. ```python import requests base_url = "https://iso3166-2-api.vercel.app/api/" input_search = "Saarland,US-CA" data = requests.get(f'{base_url}/search_geo/{input_search}').json() data["DE-SL"] # Saarland data["US-CA"] # California ``` -------------------------------- ### Search with likeness parameter (Python Requests) Source: https://github.com/amckenna41/iso3166-2/blob/main/docs/api.rst Searches for subdivisions with 'Northern' or 'Southern' in their name using the likeness query parameter set to 80. The example uses the /search endpoint with params={'likeness': 80}. ```python import requests base_url = "https://iso3166-2-api.vercel.app/api/" input_search = "Northern" #Southern all_data = requests.get(f'{base_url}/search/{input_search}', params={"likeness": 80).json() ``` -------------------------------- ### GET /api/list_subdivisions - curl request and response Source: https://github.com/amckenna41/iso3166-2/blob/main/API.md Retrieves all ISO 3166-2 subdivision codes for all countries. The response is a JSON object with country codes as keys and arrays of subdivision codes as values. ```bash curl -i https://iso3166-2-api.vercel.app/api/list_subdivisions ``` ```http HTTP/2 200 content-type: application/json date: Sat, 03 Feb 2025 15:03:11 GMT server: Vercel content-length: {"AD":{"AD-02","AD-03"...}} ``` -------------------------------- ### Using the Geo class to retrieve and export ISO 3166-2 subdivision data Source: https://github.com/amckenna41/iso3166-2/blob/main/scripts/README.md Shows how to instantiate the Geo class with verbose output and call its key methods: get_centroid, get_bounding_box, get_visualisation_url, export_geojson, get_neighbors, get_perimeter_km, get_relation_id_from_coords, and export_all. The verbose parameter can be set at initialization or overridden per method call. ```python from scripts.geo import Geo # Create instance with verbose output enabled geo = Geo("US-CA", verbose=True) # Get centroid coordinates centroid = geo.get_centroid() print(f"Centroid: {centroid}") # Returns (lat, lon) tuple # Get bounding box bbox = geo.get_bounding_box() print(f"Bounding Box: {bbox}") # Returns dict with minLat, maxLat, minLon, maxLon # Get OpenStreetMap visualization URL url = geo.get_visualisation_url() print(f"OSM URL: {url}") # Export GeoJSON to file geo.export_geojson(out_path="california.geojson") # Get neighboring subdivisions neighbors = geo.get_neighbors() print(f"Neighbors: {neighbors}") # Get perimeter in kilometers perimeter = geo.get_perimeter_km() print(f"Perimeter: {perimeter} km") # Find subdivision from coordinates relation_id = geo.get_relation_id_from_coords(37.7749, -122.4194, admin_level=4) print(f"Relation ID: {relation_id}") # Export all geographic data all_data = geo.export_all(out_geojson_path="california_full.geojson") print(all_data) # Override class-level verbose for specific method geo_quiet = Geo("GB-ENG", verbose=False) centroid = geo_quiet.get_centroid(verbose=True) # This call will print verbose output ``` -------------------------------- ### GET /api/list_subdivisions Source: https://github.com/amckenna41/iso3166-2/blob/main/API.md Retrieves all ISO 3166-2 subdivision codes for all countries, or for a specific country if a country code is provided. The response is a JSON object with country codes as keys and arrays of subdivision codes as values. ```APIDOC ## GET /api/list_subdivisions ### Description Retrieves all ISO 3166-2 subdivision codes for all countries, or for a specific country if a country code is provided. ### Method GET ### Endpoint https://iso3166-2-api.vercel.app/api/list_subdivisions ### Parameters #### Path Parameters - **country_code** (string) - Optional - The ISO 3166-1 alpha-2 country code (e.g., LK) to filter subdivisions for a specific country. ### Request Example ``` curl -i https://iso3166-2-api.vercel.app/api/list_subdivisions ``` ### Response #### Success Response (200) - **content-type**: application/json - **body**: JSON object with country codes as keys and arrays of subdivision codes as values. #### Response Example ``` {"AD":{"AD-02","AD-03"...}} ``` ``` -------------------------------- ### Fetch subdivision data by numeric code 398 (curl and response) Source: https://github.com/amckenna41/iso3166-2/blob/main/API.md Curl request to GET /api/alpha/398. The response is HTTP/2 200 with JSON body containing subdivision data for Kazakhstan (KZ). ```bash curl -i https://iso3166-2-api.vercel.app/api/alpha/398 ``` ```http HTTP/2 200 content-type: application/json date: Fri, 22 Dec 2024 19:40:10 GMT server: Vercel content-length: 2922 {"KZ":{"KZ-10":{"..."}}} ``` -------------------------------- ### Import and create Subdivisions instance Source: https://github.com/amckenna41/iso3166-2/blob/main/iso3166_2/README.md Import the iso3166_2 module and create an instance of the Subdivisions class to access subdivision data. ```python from iso3166_2 import * #create instance of Subdivisions class iso = Subdivisions() ``` -------------------------------- ### Search excluding matchScore (curl) Source: https://github.com/amckenna41/iso3166-2/blob/main/docs/api.rst Uses curl to search for subdivisions with 'Northern' in their name, excluding the matchScore attribute. Note: the example uses 'Northern' instead of 'Saint George' as in the Python example. ```default $ curl -i https://iso3166-2-api.vercel.app/api/search/Northern?likeness=80 ``` -------------------------------- ### GET /api/alpha/DE - curl request Source: https://github.com/amckenna41/iso3166-2/blob/main/API.md Retrieves subdivision data for Germany using its alpha-2 code DE. ```bash curl -i https://iso3166-2-api.vercel.app/api/alpha/DE ```