Table of Contents
What is REST Architecture?
REST stands for REpresentational State Transfer. REST is a web standards-based architecture and uses HTTP Protocol. It revolves around a resource where every component is a resource and a resource is accessed by a common interface using HTTP standard methods. REST was first introduced by Roy Fielding in 2000.
The REST architectural style emphasizes the scalability of interactions between components, uniform interfaces, independent deployment of components, and the creation of a layered architecture to facilitate caching components to reduce user-perceived latency, enforce security, and encapsulate legacy systems (Fielding, 2000).
REST has been employed throughout the software industry and is a widely accepted set of guidelines for creating stateless, reliable web services. Any web service that obeys the REST constraints is informally described as RESTful. You can experiment with Python For Absolute Beginners on using REST API in your Python applications.
What is Python’s Requests Library?
This tutorial will use Requests to send HTTP requests to each APIs.
Requests is a simple, yet elegant HTTP library. Requests allow you to execute standard HTTP requests. Using this library, you can pass parameters to requests, add headers, receive and process responses, and execute authenticated requests.
Requests is one of the most downloaded Python packages today, pulling in around 14M downloads/week—according to GitHub, Requests is currently depended upon by 500,000+ repositories. Knowing these facts, you may certainly put your trust in this credible library.
Read another article, which specifically talks about the Request library:
And visit this article, if you looking for Requests and other libraries for Web Scraping purposes:
How does Delphi add powerful GUI features and functionalities to Python?
In this tutorial, we’ll build Windows Apps with extensive support from apilayer’s REST services, and develop GUI for them using Python4Delphi (P4D).
P4D empowers Python users with Delphi’s award-winning VCL functionalities for Windows which enables us to build native Windows apps 5x faster. This integration enables us to create a modern GUI with Windows 10 looks and responsive controls for our Python applications. Python4Delphi also comes with an extensive range of demos, use cases, and tutorials.
We’re going to cover the following REST services…
How to build Python GUI for ipstack, mailboxlayer, scrapestack, serpstack, and weatherstack REST services?
All of them would be integrated with Python4Delphi to create Windows Apps with extensive data and capabilities.
What are the prerequisites?
Before we begin to work, download and install the latest Python for your platform. Follow the Python4Delphi installation instructions mentioned here. Alternatively, you can check out the easy instructions found in the Getting Started With Python4Delphi video by Jim McKeeth.
Time to get started!
First, open and run our Python GUI using project Demo1 from Python4Delphi with RAD Studio. Then insert the script into the lower Memo, click the Execute button, and get the result in the upper Memo. You can find the Demo1 source on GitHub. The behind the scene details of how Delphi manages to run your Python code in this amazing Python GUI can be found at this link.
How to build a Python GUI for ipstack API?
ipstack offers a powerful, real-time IP to geolocation API capable of looking up accurate location data and assessing security threats originating from risky IP addresses. The results are delivered within milliseconds in JSON or XML format. Using the ipstack API you will be able to locate website visitors automatically and adjust your user experience and application accordingly.
The following is a code example for interacting with ipstack API (run this inside the lower Memo of Python4Delphi Demo01 GUI):
1 2 3 4 5 6 |
import requests r = requests.get("http://api.ipstack.com/134.201.250.155?access_key=YOUR_ACCESS_KEY") responses = r.json() print(responses) |
What does the result look like in Python GUI?
Where can I read about more implementations of the IPStack API?
How do I build a Python GUI for mailboxlayer API?
mailboxlayer is a free, simple, and powerful JSON API offering instant email address validation & verification via syntax checks, typo, and spelling checks, SMTP checks, free and disposable provider filtering, and much more. Its system is REST-based, secured by 256-bit HTTPS encryption, and pursuing the goal of assisting developers and businesses in fighting fraudulent users and increasing success rates of email campaigns.
The following is a code example for interacting with mailboxlayer API (run this inside the lower Memo of Python4Delphi Demo01 GUI):
1 2 3 4 5 6 7 8 9 10 11 |
import requests params = { 'access_key': 'YOUR_ACCESS_KEY', } api_result = requests.get('http://apilayer.net/api/check?', params) api_response = api_result.json() print(api_response) |
What does the mailboxlayer example look like in the Python GUI?
Where to find more examples of using the Mailboxlayer API?
How can I build a Python GUI for scrapestack API?
The scrapestack API was built to offer a simple REST API interface for scraping web pages at scale without having to programmatically deal with geolocations, IP blocks, or CAPTCHAs. The API supports a series of features essential to web scrapings, such as JavaScript rendering, custom HTTP headers, various geo-targets, POST/PUT requests, and an option to use premium residential proxies instead of datacenter proxies.
The following is a code example for interacting with scrapestack API (run this inside the lower Memo of Python4Delphi Demo01 GUI):
1 2 3 4 5 6 7 8 9 10 11 |
import requests params = { 'access_key': 'YOUR_ACCESS_KEY', 'url': 'https://pythongui.org' } api_result = requests.get('http://api.scrapestack.com/scrape', params) website_content = api_result.content print(website_content) |
What do the scrapestack + Python4Delphi results look like?
How to build a Python GUI for serpstack API?
serpstack is an API service built to deliver real-time SERP data from all major search engines worldwide, including Google, Yahoo, Bing, Baidu & Yandex. You can use the serpstack API to scrape SERP data at scale using options like location, browser, device, and more. Minimal implementation takes just a few seconds using the simple HTTP GET URL structure, and results are returned in JSON.
The following is a code example for interacting with serpstack API (run this inside the lower Memo of Python4Delphi Demo01 GUI):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
import requests params = { 'access_key': 'YOUR_ACCESS_KEY', 'query': 'pythongui' } api_result = requests.get('http://api.serpstack.com/search', params) api_response = api_result.json() print("Total results: ", api_response['search_information']['total_results']) for number, result in enumerate(api_response['organic_results'], start=1): print("%s. %s" % (number, result['title'])) #print(u'Current temperature in %s is %d℃' % (api_response['location']['name'], api_response['current']['temperature'])) |
Here is an example of the serpstack API
How to build and use a Python GUI for weatherstack API?
The weatherstack API was built to deliver accurate weather data for any application and use case, from real-time and historical weather information all the way to 14-day weather forecasts, supporting all major programming languages.
The following is a code example for interacting with weatherstack API (run this inside the lower Memo of Python4Delphi Demo01 GUI):
1 2 3 4 5 6 7 8 9 10 11 12 13 |
import requests params = { 'access_key': 'YOUR_ACCESS_KEY', 'query': 'New York' } api_result = requests.get('http://api.weatherstack.com/current', params) api_response = api_result.json() print(u'Current temperature in %s is %d℃' % (api_response['location']['name'], api_response['current']['temperature'])) #print(api_response) |
What does the weatherstack demo result look like in the Python GUI?
Are you ready to build awesome things with these powerful APIs and Python4Delphi?
We already demonstrate how to build Python GUI for 5 powerful REST services provided by apilayer (ipstack, mailboxlayer, scrapestack, serpstack, and weatherstack). All of them wrapped well inside a powerful GUI provided by Python4Delphi. We can’t wait to see what you build with Python4Delphi!
Want to know some more? Then check out Python4Delphi which easily allows you to build Python GUIs for Windows using Delphi, and
Download RAD Studio to build more powerful Python GUI Windows Apps 5x Faster with Less Code.