Skip to main content

APIBridge

Joining json API calls together


Build Status codecov PyPI version MIT License


Installation

pip install api_bridge

Usage

The API-class

API(url: str,
    method: Method = Method.GET,
    result_filter: Optional[Callable[[Dict[str, Any]], Dict[str, Any]]] = None,
    validate: Optional[Callable[[Dict[str, Any]], bool]] = None,
    post_data: Optional[Dict[str, Any]] = None
    )

url The url to run a request with

method The Enum from api_bridge.methods.Method [either Method.GET or .POST; defaults to .GET]

result_filter A filter for the retrieved json data api_bridge.filter.Filter [defaults to None]


Filter(**out: str)

out The items of the filtered data

examples:

Filter(lat='latitude', long='longitude')  # {'lat': data['latitude'], 'long': data['longitude']}

Filter(sunrise='results sunrise')  # spaces represent {'sunrise': data['results]['sunrise']}

validate An additional test based on the received data in addition to the http-status-code [defaults to None]

example:

validate=lambda data: data['status'] == 'successful'

post_data Data if Method.POST was provided

Requests

There are two ways to run a request

from api_bridge.api import API
from api_bridge.filter import Filter
from api_bridge.container import Container

LOCATION_URL = 'https://ipapi.co/json/'
TIME_URL = 'https://api.sunrise-sunset.org/json?lat={lat}&lng={long}&date=today'

The chain-method

result = API.chain(
            API(LOCATION_URL, result_filter=Filter(lat='latitude', long='longitude')),
            API(TIME_URL, validate=lambda response: response['status'] == 'OK', result_filter=Filter(sunrise='results sunrise'))
         )

result == {'sunrise': '4:08:10 AM'}

The (esoteric) operator-method > or >>

result = API('https://ipapi.co/json/', result_filter=Filter(lat='latitude', long='longitude')) > \
                API('https://api.sunrise-sunset.org/json?lat={lat}&lng={long}&date=today', validate=lambda response:
                    response['status'] == 'OK', result_filter=Filter(sunrise='results sunrise')) > \
                Container()

result == {'sunrise': '4:08:10 AM'}

Important the gt and rshift operator mehtod must terminate with an Operator(), which can be treated a dict afterwards

Metadata

Release files for api-bridge 0.0.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for api-bridge 0.0.7
File Size Uploaded Provenance
api_bridge-0.0.7.tar.gz 5.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for api-bridge 0.0.7
File Interpreter ABI Platform
api_bridge-0.0.7-py3-none-any.whl Python 3 none any Details

Total release size: 13.3 kB

Release files / api_bridge-0.0.7.tar.gz

Download URL api_bridge-0.0.7.tar.gz
Size 5.7 kB
Tags Source
SHA-256 checksum
How to use checksums
f1fc8a7fd5318bc031047e8ec798be194364b232946590cc2ae8109f36bd2fd5
BLAKE2b-256 checksum
How to use checksums
c49f91b7fd0ba7e897ea38f41c3a34028cd3bcf74b49252ab427469c2e6029f7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.2

Release files / api_bridge-0.0.7-py3-none-any.whl

Download URL api_bridge-0.0.7-py3-none-any.whl
Size 7.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6f55add339f21ab2e19459662124f3673edda48f526acbdb074248a3810a39da
BLAKE2b-256 checksum
How to use checksums
b7d6f4c5a0fa2ec06d54eab9d8099513810293267fc89adea41199ecb3368b2c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.2

Security for api-bridge 0.0.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page