Skip to content

Commit 66d74b0

Browse files
authored
Doc/project documentation (#38)
* Add project documentation * Add readthedocs configuration * Fix Python code blocks highlighting
1 parent a42a73c commit 66d74b0

File tree

93 files changed

+1392
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+1392
-1
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,6 @@ __pycache__/
1515

1616
# Tox
1717
.tox
18+
19+
# Docs build
20+
docs/build/

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
fail_fast: true
2+
exclude: ^(docs|README\.md)/
23
repos:
34
- repo: https://github.com/pre-commit/pre-commit-hooks
45
rev: v4.5.0

.readthedocs.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: 2
2+
3+
build:
4+
os: ubuntu-22.04
5+
tools:
6+
python: "3.9"
7+
8+
sphinx:
9+
configuration: docs/source/conf.py
10+
11+
python:
12+
install:
13+
- requirements: docs/requirements.txt

README.md

Lines changed: 256 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,256 @@
1-
# TODO
1+
# Abstract API Python SDK
2+
3+
This is a simple and intuitive Python SDK for using [AbstractAPI's](https://www.abstractapi.com/) services.
4+
5+
Current supported services:
6+
===========================
7+
All AbstractAPI services are supported by this SDK (16th. January 2023).
8+
- Email Validation
9+
- Phone Validation
10+
- VAT Validation/Calculation/Categories
11+
- IBAN Validation
12+
- IP Geolocation
13+
- Holidays Lookup
14+
- Exchange Rates Live/Convert/Historical
15+
- Company Enrichment
16+
- Timezone Current/Conversion
17+
- Avatars Generation
18+
- Website Screenshot
19+
- Website Scrape
20+
- Image Processing
21+
22+
Installation:
23+
=============
24+
Install using `pip`:
25+
26+
pip install abstract-api
27+
28+
Getting Started:
29+
================
30+
To use any service, you must have your API key for that service.\
31+
To do that, you have two options:
32+
1. Export your API key as an environment variable:\
33+
To export an API key for a service, you should follow this scheme:
34+
```
35+
ABSTRACTAPI_{SERVICE_NAME}_API_KEY
36+
```
37+
Note: `SERVICE_NAME` is all uppercase and underscore separated.\
38+
For example, to export your Email Validation service API key, use the following environment variable name:
39+
```
40+
ABSTRACTAPI_EMAIL_VALIDATION_API_KEY
41+
```
42+
Example in terminal:
43+
```shell
44+
export ABSTRACTAPI_AVATARS_API_KEY=612345e4a63044b47a1234567a53cc81
45+
```
46+
In initialization, you don't have to pass an API key:
47+
```python
48+
from abstract_api import EmailValidation
49+
50+
service = EmailValidation()
51+
```
52+
2. Pass your API key during service class instantiation:\
53+
Example:
54+
```python
55+
from abstract_api import EmailValidation
56+
57+
service = EmailValidation(api_key="612345e4a63044b47a1234567a53cc81")
58+
```
59+
60+
**Note**:
61+
If both options were used simultaneously, the API key that was passed to constructor is used.
62+
63+
Examples:
64+
=========
65+
**Notes**:
66+
- Each service response is represented as a response class to provide an intuitive\
67+
Pythonic way for handling responses.
68+
- All public interfaces of all services classes are modeled after AbstractAPI endpoints interfaces and responses.\
69+
Example: Email Validation service endpoint expects the following parameters:
70+
- `api_key`
71+
- `email`
72+
- `auto_correct`\
73+
The `EmailValidation` class's `check()` method expects the same parameters `email` and `auto_correct`.\
74+
(No need to pass `api_key`. It is already passed during service instantiation.)
75+
76+
**Recommended**:\
77+
- Check service class and service class response documentations.
78+
- Response fields used in examples are not only the ones. Check documentation to see\
79+
all the capabilities.
80+
81+
- Email Validation
82+
```python
83+
from abstract_api import EmailValidation
84+
service = EmailValidation(api_key="612345e4a63044b47a1234567a53cc81")
85+
response = service.check("example@example.com")
86+
if response.is_valid_format:
87+
print("Email is valid!")
88+
if response.is_disposable_email:
89+
print("Email is disposable, not this time :( ")
90+
```
91+
`EmailValidation` documentation can be found [here](TODO)\
92+
`EmailValidationResponse` documentation can be found [here](TODO)
93+
94+
- Phone Validation
95+
```python
96+
from abstract_api import PhoneValidation
97+
service = PhoneValidation(api_key="612345e4a63044b47a1234567a53cc81")
98+
response = service.check("20123456789")
99+
if response.valid:
100+
print("Phone number is valid!")
101+
```
102+
`PhoneValidation` documentation can be found [here](TODO)\
103+
`PhoneValidationResponse` documentation can be found [here](TODO)
104+
105+
- VAT Validation/Calculation/Inquiry
106+
```python
107+
from abstract_api import VAT
108+
service = VAT(api_key="612345e4a63044b47a1234567a53cc81")
109+
validation_response = service.check("SE556656688001")
110+
calculation_response = service.calculate(amount=100, country_code="EG")
111+
categories_response = service.categories("EG")
112+
```
113+
`VAT` documentation can be found [here](TODO)\
114+
`VATValidationResponse` documentation can be found [here](TODO)\
115+
`VATCalculationResponse` documentation can be found [here](TODO)\
116+
`VATCategoriesResponse` documentation can be found [here](TODO)
117+
118+
- IBAN Validation
119+
```python
120+
from abstract_api import IBANValidation
121+
service = IBANValidation(api_key="612345e4a63044b47a1234567a53cc81")
122+
response = service.check("BE71096123456769")
123+
if response.is_valid:
124+
print("IBAN is valid!")
125+
```
126+
`IBANValidation` documentation can be found [here](TODO)\
127+
`IBANValidationResponse` documentation can be found [here](TODO)
128+
129+
- IP Geolocation
130+
```python
131+
from abstract_api import IPGeolocation
132+
service = IPGeolocation(api_key="612345e4a63044b47a1234567a53cc81")
133+
response = service.check("156.215.70.7", fields=["city"])
134+
print("IP is in: ", response.city)
135+
```
136+
`IPGeolocation` documentation can be found [here](TODO)\
137+
`IPGeolocationResponse` documentation can be found [here](TODO)
138+
139+
- Holidays Lookup
140+
```python
141+
from abstract_api import Holidays
142+
service = Holidays(api_key="612345e4a63044b47a1234567a53cc81")
143+
response = service.check("EG")
144+
print(response.holidays)
145+
```
146+
`Holidays` documentation can be found [here](TODO)\
147+
`HolidaysResponse` documentation can be found [here](TODO)
148+
149+
- Exchange Rates Live/Convert/Historical
150+
```python
151+
from abstract_api import ExchangeRates
152+
service = ExchangeRates(api_key="612345e4a63044b47a1234567a53cc81")
153+
live_response = service.live("USD", "EGP")
154+
conversion_response = service.convert("USD", "EGP", "2023-01-17", 150)
155+
historical_response = service.historical("USD", "2023-01-17", 150)
156+
```
157+
`ExchangeRates` documentation can be found [here](TODO)\
158+
`LiveExchangeRatesResponse` documentation can be found [here](TODO)\
159+
`HistoricalExchangeRatesResponse` documentation can be found [here](TODO)\
160+
`ExchangeRatesConversionResponse` documentation can be found [here](TODO)
161+
162+
- Company Enrichment
163+
```python
164+
from abstract_api import CompanyEnrichment
165+
service = CompanyEnrichment(api_key="612345e4a63044b47a1234567a53cc81")
166+
response = service.check("EG")
167+
print(response.holidays)
168+
```
169+
`CompanyEnrichment` documentation can be found [here](TODO)\
170+
`CompanyEnrichmentResponse` documentation can be found [here](TODO)
171+
172+
- Timezone Current/Conversion
173+
```python
174+
from abstract_api import Timezone
175+
service = Timezone(api_key="612345e4a63044b47a1234567a53cc81")
176+
current_response = service.current("Cairo, Egypt", "82.111.111.111")
177+
conversion_response = service.convert((30.0594627, 31.1758899), "Cairo, Egypt")
178+
```
179+
`Timezone` documentation can be found [here](TODO)\
180+
`CurrentTimezoneResponse` documentation can be found [here](TODO)\
181+
`TimezoneConversionResponse` documentation can be found [here](TODO)
182+
183+
- Avatars Generation
184+
```python
185+
from abstract_api import Avatars
186+
service = Avatars(api_key="612345e4a63044b47a1234567a53cc81")
187+
response = service.create("John Doe", 200)
188+
file = open("logo.png", "wb+")
189+
file.write(response.content)
190+
```
191+
`Avatars` documentation can be found [here](TODO)\
192+
`AvatarsResponse` documentation can be found [here](TODO)
193+
194+
- Website Screenshot
195+
```python
196+
from abstract_api import WebsiteScreenshot
197+
service = WebsiteScreenshot(api_key="612345e4a63044b47a1234567a53cc81")
198+
response = service.capture("https://www.github.com", capture_full_page=False)
199+
file = open("github-home-screenshot.png", "wb+")
200+
file.write(response.content)
201+
```
202+
`WebsiteScreenshot` documentation can be found [here](TODO)\
203+
`WebsiteScreenshotResponse` documentation can be found [here](TODO)
204+
205+
- Website Scrape
206+
```python
207+
from abstract_api import WebScraping
208+
service = WebScraping(api_key="612345e4a63044b47a1234567a53cc81")
209+
response = service.scrape("https://www.github.com", proxy_country="EG")
210+
file = open("github-home-screenshot.png", "wb+")
211+
file.write(response.content)
212+
```
213+
`WebScraping` documentation can be found [here](TODO)\
214+
`WebScrapingResponse` documentation can be found [here](TODO)
215+
216+
- Image Processing
217+
```python
218+
from abstract_api import ImageProcessing
219+
from abstract_api.image_processing.strategies import Crop, Exact
220+
resize = Exact(height=200, width=200)
221+
service = ImageProcessing(api_key="612345e4a63044b47a1234567a53cc81")
222+
image = open('example.png', 'rb')
223+
response = service.upload(image, lossy=False, resize=resize)
224+
print(response.url)
225+
response = service.url("https://example.com/image.jpeg", lossy=False, resize=resize)
226+
print(response.url)
227+
```
228+
`ImageProcessing` documentation can be found [here](TODO)\
229+
`ImageProcessingResponse` documentation can be found [here](TODO)
230+
231+
### Handling Errors
232+
1. If something wrong happened on client side:
233+
```python
234+
from abstract_api import ImageProcessing
235+
from abstract_api.core.exceptions import ClientRequestError
236+
service = ImageProcessing(api_key="612345e4a63044b47a1234567a53cc81")
237+
try:
238+
service.url("https://example.com/image.jpeg", quality=150)
239+
except ClientRequestError as e:
240+
print("Some error happended from client's side")
241+
print(str(e))
242+
'quality must be in range from 1 to 100 (inclusive)'
243+
```
244+
2. If the service endpoint returns a status code that is not 200 or 204.\
245+
(200 and 204 are -currently- the only accepted status codes.)
246+
```python
247+
from abstract_api import ImageProcessing
248+
from abstract_api.core.exceptions import APIRequestError
249+
service = ImageProcessing(api_key="612345e4a63044b47a1234567a53cc81")
250+
try:
251+
service.url("https://example.com/image.jpeg", quality=150)
252+
except APIRequestError as e:
253+
if e.status_code == 500:
254+
print("AbstractAPI service is currently having a problem")
255+
print(str(e))
256+
```

docs/Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Minimal makefile for Sphinx documentation
2+
#
3+
4+
# You can set these variables from the command line, and also
5+
# from the environment for the first two.
6+
SPHINXOPTS ?=
7+
SPHINXBUILD ?= sphinx-build
8+
SOURCEDIR = source
9+
BUILDDIR = build
10+
11+
# Put it first so that "make" without argument is like "make help".
12+
help:
13+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14+
15+
.PHONY: help Makefile
16+
17+
# Catch-all target: route all unknown targets to Sphinx using the new
18+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19+
%: Makefile
20+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

docs/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Developing Documentation
2+
3+
4+
Installation:
5+
=============
6+
After installing the SDK, install docs requirements (docs/requirements.txt) using `pip`:
7+
8+
pip install -r requirements.txt
9+
10+
Getting Started:
11+
================
12+
In `docs` directory, run `make html` to generate HTML documentation.

docs/make.bat

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
@ECHO OFF
2+
3+
pushd %~dp0
4+
5+
REM Command file for Sphinx documentation
6+
7+
if "%SPHINXBUILD%" == "" (
8+
set SPHINXBUILD=sphinx-build
9+
)
10+
set SOURCEDIR=source
11+
set BUILDDIR=build
12+
13+
%SPHINXBUILD% >NUL 2>NUL
14+
if errorlevel 9009 (
15+
echo.
16+
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
17+
echo.installed, then set the SPHINXBUILD environment variable to point
18+
echo.to the full path of the 'sphinx-build' executable. Alternatively you
19+
echo.may add the Sphinx directory to PATH.
20+
echo.
21+
echo.If you don't have Sphinx installed, grab it from
22+
echo.https://www.sphinx-doc.org/
23+
exit /b 1
24+
)
25+
26+
if "%1" == "" goto help
27+
28+
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
29+
goto end
30+
31+
:help
32+
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
33+
34+
:end
35+
popd

docs/requirements.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
alabaster==0.7.16
2+
Babel==2.14.0
3+
beautifulsoup4==4.12.3
4+
docutils==0.20.1
5+
furo==2023.9.10
6+
imagesize==1.4.1
7+
importlib-metadata==7.0.1
8+
Jinja2==3.1.3
9+
markdown-it-py==3.0.0
10+
MarkupSafe==2.1.3
11+
mdit-py-plugins==0.4.0
12+
mdurl==0.1.2
13+
myst-parser==2.0.0
14+
Pygments==2.17.2
15+
snowballstemmer==2.2.0
16+
soupsieve==2.5
17+
Sphinx==7.2.6
18+
sphinx-basic-ng==1.0.0b2
19+
sphinxcontrib-applehelp==1.0.8
20+
sphinxcontrib-devhelp==1.0.6
21+
sphinxcontrib-htmlhelp==2.0.5
22+
sphinxcontrib-jsmath==1.0.1
23+
sphinxcontrib-qthelp==1.0.7
24+
sphinxcontrib-serializinghtml==1.1.10
25+
zipp==3.17.0
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
abstract\_api.avatars.avatars module
2+
====================================
3+
4+
.. automodule:: abstract_api.avatars.avatars
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
abstract\_api.avatars.avatars\_response module
2+
==============================================
3+
4+
.. automodule:: abstract_api.avatars.avatars_response
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:

0 commit comments

Comments
 (0)