Package: abstract-api
Abstract API Python SDKThis is a simple and intuitive Python SDK for usingAbstractAPI'sservices.Current supported services:All AbstractAPI services are supported by this SDK (16th. January 2023).Email ValidationPhone ValidationVAT Validation/Calculation/CategoriesIBAN ValidationIP GeolocationHolidays LookupExchange Rates Live/Convert/HistoricalCompany EnrichmentTimezone Current/ConversionAvatars GenerationWebsite ScreenshotWebsite ScrapeImage ProcessingInstallation:Install usingpip:pip install abstract-apiGetting 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:ABSTRACTAPI_{SERVICE_NAME}_API_KEYNote:SERVICE_NAMEis all uppercase and underscore separated.For example, to export your Email Validation service API key, use the following environment variable name:ABSTRACTAPI_EMAIL_VALIDATION_API_KEYExample in terminal:exportABSTRACTAPI_AVATARS_API_KEY=612345e4a63044b47a1234567a53cc81In initialization, you don't have to pass an API key:fromabstract_apiimportEmailValidationservice=EmailValidation()Pass your API key during service class instantiation:Example:fromabstract_apiimportEmailValidationservice=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 intuitivePythonic 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_correctTheEmailValidationclass'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 seeall the capabilities.Email Validationfromabstract_apiimportEmailValidationservice=EmailValidation(api_key="612345e4a63044b47a1234567a53cc81")response=service.check("example@example.com")ifresponse.is_valid_format:print("Email is valid!")ifresponse.is_disposable_email:print("Email is disposable, not this time :( ")EmailValidationdocumentation can be foundhereEmailValidationResponsedocumentation can be foundherePhone Validationfromabstract_apiimportPhoneValidationservice=PhoneValidation(api_key="612345e4a63044b47a1234567a53cc81")response=service.check("20123456789")ifresponse.valid:print("Phone number is valid!")PhoneValidationdocumentation can be foundherePhoneValidationResponsedocumentation can be foundhereVAT Validation/Calculation/Inquiryfromabstract_apiimportVATservice=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 foundhereVATValidationResponsedocumentation can be foundhereVATCalculationResponsedocumentation can be foundhereVATCategoriesResponsedocumentation can be foundhereIBAN Validationfromabstract_apiimportIBANValidationservice=IBANValidation(api_key="612345e4a63044b47a1234567a53cc81")response=service.check("BE71096123456769")ifresponse.is_valid:print("IBAN is valid!")IBANValidationdocumentation can be foundhereIBANValidationResponsedocumentation can be foundhereIP Geolocationfromabstract_apiimportIPGeolocationservice=IPGeolocation(api_key="612345e4a63044b47a1234567a53cc81")response=service.check("156.215.70.7",fields=["city"])print("IP is in: ",response.city)IPGeolocationdocumentation can be foundhereIPGeolocationResponsedocumentation can be foundhereHolidays Lookupfromabstract_apiimportHolidaysservice=Holidays(api_key="612345e4a63044b47a1234567a53cc81")response=service.check("EG")print(response.holidays)Holidaysdocumentation can be foundhereHolidaysResponsedocumentation can be foundhereExchange Rates Live/Convert/Historicalfromabstract_apiimportExchangeRatesservice=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 foundhereLiveExchangeRatesResponsedocumentation can be foundhereHistoricalExchangeRatesResponsedocumentation can be foundhereExchangeRatesConversionResponsedocumentation can be foundhereCompany Enrichmentfromabstract_apiimportCompanyEnrichmentservice=CompanyEnrichment(api_key="612345e4a63044b47a1234567a53cc81")response=service.check("EG")print(response.holidays)CompanyEnrichmentdocumentation can be foundhereCompanyEnrichmentResponsedocumentation can be foundhereTimezone Current/Conversionfromabstract_apiimportTimezoneservice=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 foundhereCurrentTimezoneResponsedocumentation can be foundhereTimezoneConversionResponsedocumentation can be foundhereAvatars Generationfromabstract_apiimportAvatarsservice=Avatars(api_key="612345e4a63044b47a1234567a53cc81")response=service.create("John Doe",200)file=open("logo.png","wb+")file.write(response.content)Avatarsdocumentation can be foundhereAvatarsResponsedocumentation can be foundhereWebsite Screenshotfromabstract_apiimportWebsiteScreenshotservice=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 foundhereWebsiteScreenshotResponsedocumentation can be foundhereWebsite Scrapefromabstract_apiimportWebScrapingservice=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 foundhereWebScrapingResponsedocumentation can be foundhereImage Processingfromabstract_apiimportImageProcessingfromabstract_api.image_processing.strategiesimportCrop,Exactresize=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 foundhereImageProcessingResponsedocumentation can be foundhereHandling ErrorsIf something wrong happened on client side:fromabstract_apiimportImageProcessingfromabstract_api.core.exceptionsimportClientRequestErrorservice=ImageProcessing(api_key="612345e4a63044b47a1234567a53cc81")try:service.url("https://example.com/image.jpeg",quality=150)exceptClientRequestErrorase: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.)fromabstract_apiimportImageProcessingfromabstract_api.core.exceptionsimportAPIRequestErrorservice=ImageProcessing(api_key="612345e4a63044b47a1234567a53cc81")try:service.url("https://example.com/image.jpeg",quality=150)exceptAPIRequestErrorase:ife.status_code==500:print("AbstractAPI service is currently having a problem")print(str(e))