GlobalIDPAPI - This Python Code Allows You To Access The Global API and Get The Result in Different Format (CSV, XLSX, and JSON)
GlobalIDPAPI - This Python Code Allows You To Access The Global API and Get The Result in Different Format (CSV, XLSX, and JSON)
Aschalew /
GlobalIDPAPI
Code Issues Pull requests Actions Projects Wiki Security Insights Setting
This Python code allows you to access the Global API and get the result in different format(csv, xlsx, and JSON)
Public repository
README
Code Description
Features
Fetches data from DTM API with customizable parameters.
Supports saving data in JSON, CSV, or XLSX formats.
Allows specifying output directory and file names for easy data organization.
Requirements
Python 3.x
https://github.com/Aschalew/GlobalIDPAPI/tree/main 1/4
11/25/24, 10:05 PM Aschalew/GlobalIDPAPI: This Python code allows you to access the Global API and get the result in different format(csv, xlsx, an…
requests
pandas
Usage
Configuration
1. API URL: The API URL is set to fetch Admin 0 level data by default. Change the URL in the script for
different administrative levels:
Admin 0: https://dtmapi.iom.int/api/idpAdmin0Data/GetAdmin0Datav2
Admin 1: https://dtmapi.iom.int/api/IdpAdmin1Data/GetAdmin1Datav2
Admin 2: https://dtmapi.iom.int/api/IdpAdmin2Data/GetAdmin2Datav2
2. Parameters: Adjust the parameters in the params dictionary to filter data by country code,
administrative level, reporting dates, and other optional fields.
Example params :
params = {
'CountryName': '',
'Admin0Pcode': 'AFG', # Example for Afghanistan
'Operation': '',
'FromReportingDate': '',
'ToReportingDate': '',
'Admin1Name': '',
'Admin1Pcode': '',
'Admin2Name': '',
'Admin2Pcode': '',
'FromRoundNumber': '',
'ToRoundNumber': ''
}
3. Output Format: Set the format_type variable to specify the output format ( 'json' , 'csv' , or 'xlsx' ).
4. Output Location: By default, files are saved to a folder named api_data on your desktop. Change the
output_dir variable to a different path if desired.
python script_name.py
https://github.com/Aschalew/GlobalIDPAPI/tree/main 2/4
11/25/24, 10:05 PM Aschalew/GlobalIDPAPI: This Python code allows you to access the Global API and get the result in different format(csv, xlsx, an…
Example
To fetch and save data as a CSV file:
params = {
'Admin0Pcode': 'AFG' # Specify the country or any other required parameters
}
format_type = 'csv'
Functions
fetch_data(api_url, params)
Description: Sends a GET request to the specified API with the given parameters.
Parameters:
api_url : API endpoint URL.
Error Handling
If a required parameter (such as CountryName , Admin0Pcode , or Operation ) is missing, the script will raise a
ValueError . Additionally, any issues during the API request or file saving process will be caught and printed.
Releases
No releases published
Create a new release
https://github.com/Aschalew/GlobalIDPAPI/tree/main 3/4
11/25/24, 10:05 PM Aschalew/GlobalIDPAPI: This Python code allows you to access the Global API and get the result in different format(csv, xlsx, an…
Packages
No packages published
Publish your first package
Languages
Python 100.0%
Suggested workflows
Based on your tech stack
https://github.com/Aschalew/GlobalIDPAPI/tree/main 4/4