Catalog PyPI
Back to packageRELEASE DETAILS

1.7.0

PyPI

aio-apiclient

Async helper to work with HTTP APIs

apiclientasynciocuriomuffintrio
Published3 Feb 2023
Direct dependencies8
Transitive dependenciesNot calculated

README

Version 1.7.0 documentation
aio-apiclient
#############

.. _description:

aio-apiclient -- Async helper to work with HTTP APIs

.. _badges:

.. image:: https://github.com/klen/aio-apiclient/workflows/tests/badge.svg
    :target: https://github.com/klen/aio-apiclient/actions
    :alt: Tests Status

.. image:: https://img.shields.io/pypi/v/aio-apiclient
    :target: https://pypi.org/project/aio-apiclient/
    :alt: PYPI Version

.. image:: https://img.shields.io/pypi/pyversions/aio-apiclient
    :target: https://pypi.org/project/aio-apiclient/
    :alt: Python Versions

.. _features:

Features
========

- Convenient work with any HTTP API (especially with REST)
- Supports `httpx` and `aiohttp` as backends to make requests
- Very configurable and usable
- An ability to parse responses automatically

.. _contents:

.. contents::

.. _requirements:

Requirements
=============

- python >= 3.7

.. _installation:

Installation
=============

**aio-apiclient** should be installed using pip: ::

    pip install aio-apiclient

Please note that **aio-apiclient** requires any of supported http backends
(aiohttp, httpx) to be installed in order for it to work.

You may optionally install the requirements with the library: ::

    # For httpx
    pip install aio-apiclient[httpx]

    # For aiohttp
    pip install aio-apiclient[aiohttp]


.. _usage:

QuickStart
==========

Github API (https://developer.github.com/v4/):

.. code:: python

    from apiclient import APIClient

    # First available backend (aiohttp, httpx) will be used
    client = APIClient('https://api.github.com', headers={
            'Authorization': 'token OAUTH-TOKEN'
    })

    # Read information about the current repository
    repo = await client.api.repos.klen['aio-apiclient'].get()
    print(repo)  # dict parsed from Github Response JSON


Slack API (https://api.slack.com/web):

.. code:: python

    from apiclient import APIClient

    client = APIClient('https://api.github.com', headers={
        'Authorization': 'token OAUTH-TOKEN'
    })

    # Update current user status (we don't care about this response)
    await client.api['users.profile.set'].post(json={
        'profile': {
            'status_text': 'working',
            'status_emoji': ':computer:'
            'status_expiration': 30,
        }
    }, read_response_body=False)


And etc

Usage
=====

Initialization
--------------

The Client initialization requires root URL for a required API.

.. code:: python

    from apiclient import APIClient

    client = APIClient(

        # Root URL for any API (required)
        'https://api.github.com',

        # Raise `client.Error` for any response with status code > 400
        raise_for_status=True,

        # Set to `False` if you only want to make a request and doesn't care about responses
        read_response_body=True,

        # Parse response's body content-type and return JSON/TEXT/Form data instead the response itself

        # Set total timeout in seconds
        timeout=10.0,

        # Set backend type for making requests (apiclient.backends.BackendHTTPX,
        # apiclient.backends.BackendAIOHTTP) by default first available would be
        # choosen

        backend_type=None,

        # Default backend options to use with every request (headers, params, data, ...)
        # ...

    )

App Shutdown
------------

The api client support graceful shutdown. Run `await client.shutdown()` when
you are finishing your app (not necessary).


Middlewares
-----------

You are able to dinamically change request params (method, url, other backend params) using middlewares.

.. code:: python

    import time
    from apiclient import APIClient

    client = APIClient('https://api.github.com')

    @client.middleware
    async def insert_timestamp_header(method, url, options):
        options.setdefault('headers', {})
        options['headers']['X-Timestamp'] = str(time.time())
        return method, url, options


.. _bugtracker:

Bug tracker
===========

If you have any suggestions, bug reports or
annoyances please report them to the issue tracker
at https://github.com/klen/aio-apiclient/issues

.. _contributing:

Contributing
============

Development of the project happens at: https://github.com/klen/aio-apiclient

.. _license:

License
========

Licensed under a `MIT license`_.


.. _links:


.. _klen: https://github.com/klen

.. _MIT license: http://opensource.org/licenses/MIT

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 10

Native requirements
8 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
aiohttp
Environment
{
  "extras": "",
  "marker": "extra == 'aiohttp'",
  "requires_python": ">=3.7",
  "evaluation": "NOT_EVALUATED"
}
aiohttp ; extra == 'aiohttp'runtime
httpx
Environment
{
  "extras": "",
  "marker": "extra == 'httpx'",
  "requires_python": ">=3.7",
  "evaluation": "NOT_EVALUATED"
}
httpx (>=0.20.0) ; extra == 'httpx'runtime
aiohttp
Environment
{
  "extras": "",
  "marker": "extra == 'tests'",
  "requires_python": ">=3.7",
  "evaluation": "NOT_EVALUATED"
}
aiohttp ; extra == 'tests'runtime
httpx
Environment
{
  "extras": "",
  "marker": "extra == 'tests'",
  "requires_python": ">=3.7",
  "evaluation": "NOT_EVALUATED"
}
httpx ; extra == 'tests'runtime
pytest
Environment
{
  "extras": "",
  "marker": "extra == 'tests'",
  "requires_python": ">=3.7",
  "evaluation": "NOT_EVALUATED"
}
pytest ; extra == 'tests'runtime
pytest-aio
Environment
{
  "extras": "curio,trio",
  "marker": "extra == 'tests'",
  "requires_python": ">=3.7",
  "evaluation": "NOT_EVALUATED"
}
pytest-aio[curio,trio] (>=1.5.0) ; extra == 'tests'runtime
pytest-mypy
Environment
{
  "extras": "",
  "marker": "extra == 'tests'",
  "requires_python": ">=3.7",
  "evaluation": "NOT_EVALUATED"
}
pytest-mypy ; extra == 'tests'runtime
types-setuptools
Environment
{
  "extras": "",
  "marker": "extra == 'tests'",
  "requires_python": ">=3.7",
  "evaluation": "NOT_EVALUATED"
}
types-setuptools ; extra == 'tests'runtime
mock
Environment
{
  "extras": "",
  "marker": "(python_version < \"3.8\") and extra == 'tests'",
  "requires_python": ">=3.7",
  "evaluation": "NOT_EVALUATED"
}
mock ; (python_version < "3.8") and extra == 'tests'runtime
typing-extensions
Environment
{
  "extras": "",
  "marker": "(python_version < \"3.8\") and extra == 'tests'",
  "requires_python": ">=3.7",
  "evaluation": "NOT_EVALUATED"
}
typing-extensions ; (python_version < "3.8") and extra == 'tests'runtime

Distribution files

2 collected
aio_apiclient-1.7.0-py3-none-any.whl

bdist_wheel · 9.46 KB · Python py3

Source file
aio-apiclient-1.7.0.tar.gz

sdist · 7.77 KB · Python source

Source file

Repository

PENDING
klen/aio-apiclient

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 21 Oct, 11:36 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:04eaef55bfcb19e06d1a728083a89254a3ff7579c598ebbb52dd728a0e2810d0

Other collected versions

View all collected versions →