Skip to main content

Communicate with Apis is easy

Project description

ApiRequestManager

Communicate with Apis with flow

ApiRequestManager module provides ConfigPath object and RequestFactory to be able to call many apis easily

documentation

https://clemparpa.github.io

Github source page

https://github.com/clemparpa/ApiRequestManager

PyPi project page

https://pypi.org/project/ApiRequestManager/1.0.4/

Install

pip install ApiRequestManager==1.0.4

Usage

Create a Config Path Instance which contains configurations for your apis:

from ApiRequestManager import Config, ConfigPath


ConfigPath(
    Config(name="api_demo", base_url="https://api_demo_url"),
    Config(name="api_2_demo", base_url="http://api_2_demo_base")
)

Then Create Request Classes for your apis

from ApiRequestManager import RequestFactory 

ApiDemoFacotory = RequestFactory(api_name="api_demo")
Api2DemoFacotory = RequestFactory(api_name="api_2_demo")

Finally instanciate and execute requests

response =  ApiDemoFacotory(end_url="clemparpa")
response2 = Api2DemoFacotory(end_url="Zlatan")
response3 = ApiDemoFacotory(end_url="Neymar", params={"league":"2021392"})

It return requests.request objects for the following urls

response ---> "GET" https://api_demo_url/clemparpa
response2 ---> "GET" http://api_2_demo_base/Zlatan
response3 ---> "GET" https://api_demo_url/Neimar?league=2021392

if it's JSON format data, response.get_response().json() returns a dict which contains data

You can either use a Pipeline to execute many requests in a batch:

import the pipeline classes

from ApiRequestManager import ApiPipeline

then create your pipeline by inheriting ApiPipeline class (check documentation)

you need to override write method.

here it just print the pipe results

class DemoPrintPipeline(ApiPipeline):

    def write(entry_pack):
        print(entry_pack)

create a instance of the class designed

here a pipe with the ApiDemoFactory as RequestFactory and 1 second for sleeping time

(check pipelines documentation)

pipe = DemoPrintPipeline(ApiDemoFacotory, sleeping_time=1)

loading requests parameters:

parameters = [
        ("clemparpa", None),
        ("Neymar", {"league":"2021392"})
    ]

pipe.load_data(parameters)

run the pipe:

pipe.run_pipe()

execute two requests with 1 second sleeping between:

>>> "GET" https://api_demo_url/clemparpa
>>> "GET" https://api_demo_url/Neimar?league=2021392

You can also use these 2 next functions for the same result

from ApiRequestManager import make_api_pipe, run_api_pipe

demo_pipe = make_api_pipe(api_name="api_demo",
                          writer=lambda entry_pack: print(entry_pack),
                          sleeping_time=1)

log = run_api_pipe(pipe_instance=demo_pipe,
                   request_arguments=parameters)

the log variable store a containing requests which failed

Coverage

 -- coverage: platform win32, python 3.8.1-final-0 --
Name                               Stmts   Miss  Cover
------------------------------------------------------
ApiRequestManager\__init__.py               6      6     0%
src\ApiConfig\ApiConfig.py            12      0   100%
src\ApiConfig\UniqueDecorator.py      17      3    82%
src\ApiConfig\__init__.py              0      0   100%
src\ApiRequest\ApiRequest.py          51      4    92%
src\ApiRequest\__init__.py             0      0   100%
src\Config.py                         16      0   100%
src\ConfigPath.py                      9      1    89%
src\Pipelines.py                      88     10    89%
src\RequestFactory.py                 16      0   100%
src\__init__.py                        0      0   100%
src\make_pipe.py                      25      0   100%
------------------------------------------------------
TOTAL                                240     24    90%

coverage report with pytest-cov

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ApiRequestManager-1.0.5.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

ApiRequestManager-1.0.5-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

Details for the file ApiRequestManager-1.0.5.tar.gz.

File metadata

  • Download URL: ApiRequestManager-1.0.5.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.1

File hashes

Hashes for ApiRequestManager-1.0.5.tar.gz
Algorithm Hash digest
SHA256 54a32ec9cf8ef9cc30394a556f29ac62d4717b3be9b46807ca9c1d5843d5e7ed
MD5 f89c94fb88a2c61d723770e72dce4089
BLAKE2b-256 2e718e68a55515ee6bc83add2fe55f737740d506e35a9857959f94b437bc91c7

See more details on using hashes here.

File details

Details for the file ApiRequestManager-1.0.5-py3-none-any.whl.

File metadata

  • Download URL: ApiRequestManager-1.0.5-py3-none-any.whl
  • Upload date:
  • Size: 12.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.1

File hashes

Hashes for ApiRequestManager-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 5f609aefcc6caa5ca794867fcc1d1f3389f3b57df135739b980ce074509973b0
MD5 c0595c51068e512b1bc4b06124ecc701
BLAKE2b-256 80c2e783dc1f318d64b3cdfd65a4bde7ed95b97b6c64a95700af251d6483816c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page