Skip to main content

Communicate with Apis is Ez

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

PyPi project page

https://test.pypi.org/project/ApiRequestManager-clemparpa/0.7.1/

Install

pip install -i https://test.pypi.org/simple/ ApiRequestManager-clemparpa==0.7.1

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.1.tar.gz (9.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ApiRequestManager-1.0.1-py3-none-any.whl (12.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ApiRequestManager-1.0.1.tar.gz
  • Upload date:
  • Size: 9.2 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.1.tar.gz
Algorithm Hash digest
SHA256 68172bd752e787a967b541ca398db178a8037e1f4e129ab3bf626ce05697528a
MD5 a5bf63ebf71fcb064a953f2d0dc83154
BLAKE2b-256 4bb95ac92e8ff07d8c9fa825447cbe67a785be691cfe869eab792b5458daf7d4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ApiRequestManager-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 12.4 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2186b7be4cf0244dc2e33cb300ba63449a7240cd2ef421f8453956bef69410d8
MD5 c31cbd54809c2972e4c8fe2b60fc561c
BLAKE2b-256 06677df9259582a68a5a93033d9c92738a361a4757b2a094758cdd91e7ec2009

See more details on using hashes here.

Supported by

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