Python SDK for using AbstractAPI services
Project description
Abstract API Python SDK
This is a simple and intuitive Python SDK for using AbstractAPI's services.
Current supported services:
All AbstractAPI services are supported by this SDK (16th. January 2023).
- Email Validation
- Phone Validation
- VAT Validation/Calculation/Categories
- IBAN Validation
- IP Geolocation
- Holidays Lookup
- Exchange Rates Live/Convert/Historical
- Company Enrichment
- Timezone Current/Conversion
- Avatars Generation
- Website Screenshot
- Website Scrape
- Image Processing
Installation:
Install using pip:
pip install abstract-api
Getting Started:
To use any service, you must have your API key for that service.
To do that, you have two options:
- Export your API key as an environment variable:
To export an API key for a service, you should follow this scheme:
Note:ABSTRACTAPI_{SERVICE_NAME}_API_KEYSERVICE_NAMEis all uppercase and underscore separated.
For example, to export your Email Validation service API key, use the following environment variable name:
Example in terminal:ABSTRACTAPI_EMAIL_VALIDATION_API_KEYexport ABSTRACTAPI_AVATARS_API_KEY=612345e4a63044b47a1234567a53cc81
In initialization, you don't have to pass an API key:from abstract_api import EmailValidation service = EmailValidation()
- Pass your API key during service class instantiation:
Example:from abstract_api import EmailValidation service = EmailValidation(api_key="612345e4a63044b47a1234567a53cc81")
Note: If both options were used simultaneously, the API key that was passed to constructor is used.
Examples:
Notes:
- Each service response is represented as a response class to provide an intuitive
Pythonic way for handling responses. - All public interfaces of all services classes are modeled after AbstractAPI endpoints interfaces and responses.
Example: Email Validation service endpoint expects the following parameters:api_keyemailauto_correct
TheEmailValidationclass'scheck()method expects the same parametersemailandauto_correct.
(No need to passapi_key. It is already passed during service instantiation.)
Recommended:
-
Check service class and service class response documentations.
-
Response fields used in examples are not only the ones. Check documentation to see
all the capabilities. -
Email Validation
from abstract_api import EmailValidation service = EmailValidation(api_key="612345e4a63044b47a1234567a53cc81") response = service.check("example@example.com") if response.is_valid_format: print("Email is valid!") if response.is_disposable_email: print("Email is disposable, not this time :( ")
EmailValidationdocumentation can be found here
EmailValidationResponsedocumentation can be found here -
Phone Validation
from abstract_api import PhoneValidation service = PhoneValidation(api_key="612345e4a63044b47a1234567a53cc81") response = service.check("20123456789") if response.valid: print("Phone number is valid!")
PhoneValidationdocumentation can be found here
PhoneValidationResponsedocumentation can be found here -
VAT Validation/Calculation/Inquiry
from abstract_api import VAT service = VAT(api_key="612345e4a63044b47a1234567a53cc81") validation_response = service.check("SE556656688001") calculation_response = service.calculate(amount=100, country_code="EG") categories_response = service.categories("EG")
VATdocumentation can be found here
VATValidationResponsedocumentation can be found here
VATCalculationResponsedocumentation can be found here
VATCategoriesResponsedocumentation can be found here -
IBAN Validation
from abstract_api import IBANValidation service = IBANValidation(api_key="612345e4a63044b47a1234567a53cc81") response = service.check("BE71096123456769") if response.is_valid: print("IBAN is valid!")
IBANValidationdocumentation can be found here
IBANValidationResponsedocumentation can be found here -
IP Geolocation
from abstract_api import IPGeolocation service = IPGeolocation(api_key="612345e4a63044b47a1234567a53cc81") response = service.check("156.215.70.7", fields=["city"]) print("IP is in: ", response.city)
IPGeolocationdocumentation can be found here
IPGeolocationResponsedocumentation can be found here -
Holidays Lookup
from abstract_api import Holidays service = Holidays(api_key="612345e4a63044b47a1234567a53cc81") response = service.check("EG") print(response.holidays)
Holidaysdocumentation can be found here
HolidaysResponsedocumentation can be found here -
Exchange Rates Live/Convert/Historical
from abstract_api import ExchangeRates service = ExchangeRates(api_key="612345e4a63044b47a1234567a53cc81") live_response = service.live("USD", "EGP") conversion_response = service.convert("USD", "EGP", "2023-01-17", 150) historical_response = service.historical("USD", "2023-01-17", 150)
ExchangeRatesdocumentation can be found here
LiveExchangeRatesResponsedocumentation can be found here
HistoricalExchangeRatesResponsedocumentation can be found here
ExchangeRatesConversionResponsedocumentation can be found here -
Company Enrichment
from abstract_api import CompanyEnrichment service = CompanyEnrichment(api_key="612345e4a63044b47a1234567a53cc81") response = service.check("EG") print(response.holidays)
CompanyEnrichmentdocumentation can be found here
CompanyEnrichmentResponsedocumentation can be found here -
Timezone Current/Conversion
from abstract_api import Timezone service = Timezone(api_key="612345e4a63044b47a1234567a53cc81") current_response = service.current("Cairo, Egypt", "82.111.111.111") conversion_response = service.convert((30.0594627, 31.1758899), "Cairo, Egypt")
Timezonedocumentation can be found here
CurrentTimezoneResponsedocumentation can be found here
TimezoneConversionResponsedocumentation can be found here -
Avatars Generation
from abstract_api import Avatars service = Avatars(api_key="612345e4a63044b47a1234567a53cc81") response = service.create("John Doe", 200) file = open("logo.png", "wb+") file.write(response.content)
Avatarsdocumentation can be found here
AvatarsResponsedocumentation can be found here -
Website Screenshot
from abstract_api import WebsiteScreenshot service = WebsiteScreenshot(api_key="612345e4a63044b47a1234567a53cc81") response = service.capture("https://www.github.com", capture_full_page=False) file = open("github-home-screenshot.png", "wb+") file.write(response.content)
WebsiteScreenshotdocumentation can be found here
WebsiteScreenshotResponsedocumentation can be found here -
Website Scrape
from abstract_api import WebScraping service = WebScraping(api_key="612345e4a63044b47a1234567a53cc81") response = service.scrape("https://www.github.com", proxy_country="EG") file = open("github-home-screenshot.png", "wb+") file.write(response.content)
WebScrapingdocumentation can be found here
WebScrapingResponsedocumentation can be found here -
Image Processing
from abstract_api import ImageProcessing from abstract_api.image_processing.strategies import Crop, Exact resize = Exact(height=200, width=200) service = ImageProcessing(api_key="612345e4a63044b47a1234567a53cc81") image = open('example.png', 'rb') response = service.upload(image, lossy=False, resize=resize) print(response.url) response = service.url("https://example.com/image.jpeg", lossy=False, resize=resize) print(response.url)
ImageProcessingdocumentation can be found here
ImageProcessingResponsedocumentation can be found here
Handling Errors
- If something wrong happened on client side:
from abstract_api import ImageProcessing
from abstract_api.core.exceptions import ClientRequestError
service = ImageProcessing(api_key="612345e4a63044b47a1234567a53cc81")
try:
service.url("https://example.com/image.jpeg", quality=150)
except ClientRequestError as e:
print("Some error happended from client's side")
print(str(e))
'quality must be in range from 1 to 100 (inclusive)'
- If the service endpoint returns a status code that is not 200 or 204.
(200 and 204 are -currently- the only accepted status codes.)
from abstract_api import ImageProcessing
from abstract_api.core.exceptions import APIRequestError
service = ImageProcessing(api_key="612345e4a63044b47a1234567a53cc81")
try:
service.url("https://example.com/image.jpeg", quality=150)
except APIRequestError as e:
if e.status_code == 500:
print("AbstractAPI service is currently having a problem")
print(str(e))
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file abstract-api-1.0.0.tar.gz.
File metadata
- Download URL: abstract-api-1.0.0.tar.gz
- Upload date:
- Size: 38.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a121f389a7142e19beb052b29ba5f373c088b3da0ed51cbf4ea42182a3b67205
|
|
| MD5 |
983aae47feebffb0588d5888f59b931b
|
|
| BLAKE2b-256 |
9e9af36c8687a3e7e9d2eb43483ba63d3a16bcd5ada8dac817c41679d3a5e1d3
|
File details
Details for the file abstract_api-1.0.0-py3-none-any.whl.
File metadata
- Download URL: abstract_api-1.0.0-py3-none-any.whl
- Upload date:
- Size: 67.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3a9cba04dbb605275bf1667f259f8a03a5540a832db3947d77442bc36064a3dc
|
|
| MD5 |
6ec8f538af17c33bf738505b9a2f3f28
|
|
| BLAKE2b-256 |
3364b51dcc4d0118f8fa96bed569031b1513d63616d697bb0a4b29d9af814b50
|