aio-apiclient


Nameaio-apiclient JSON
Version 1.7.0 PyPI version JSON
download
home_pagehttps://github.com/klen/aio-apiclient
SummaryAsync helper to work with HTTP APIs
upload_time2023-02-03 07:07:44
maintainer
docs_urlNone
authorKirill Klenov
requires_python>=3.7
licenseMIT
keywords apiclient muffin asyncio trio curio
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            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


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/klen/aio-apiclient",
    "name": "aio-apiclient",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "apiclient,muffin,asyncio,trio,curio",
    "author": "Kirill Klenov",
    "author_email": "horneds@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/ec/25/fcf1dd978878398f853e34e4be7ce108cdb1d6b78e106a58c11d31896ea6/aio-apiclient-1.7.0.tar.gz",
    "platform": null,
    "description": "aio-apiclient\n#############\n\n.. _description:\n\naio-apiclient -- Async helper to work with HTTP APIs\n\n.. _badges:\n\n.. image:: https://github.com/klen/aio-apiclient/workflows/tests/badge.svg\n    :target: https://github.com/klen/aio-apiclient/actions\n    :alt: Tests Status\n\n.. image:: https://img.shields.io/pypi/v/aio-apiclient\n    :target: https://pypi.org/project/aio-apiclient/\n    :alt: PYPI Version\n\n.. image:: https://img.shields.io/pypi/pyversions/aio-apiclient\n    :target: https://pypi.org/project/aio-apiclient/\n    :alt: Python Versions\n\n.. _features:\n\nFeatures\n========\n\n- Convenient work with any HTTP API (especially with REST)\n- Supports `httpx` and `aiohttp` as backends to make requests\n- Very configurable and usable\n- An ability to parse responses automatically\n\n.. _contents:\n\n.. contents::\n\n.. _requirements:\n\nRequirements\n=============\n\n- python >= 3.7\n\n.. _installation:\n\nInstallation\n=============\n\n**aio-apiclient** should be installed using pip: ::\n\n    pip install aio-apiclient\n\nPlease note that **aio-apiclient** requires any of supported http backends\n(aiohttp, httpx) to be installed in order for it to work.\n\nYou may optionally install the requirements with the library: ::\n\n    # For httpx\n    pip install aio-apiclient[httpx]\n\n    # For aiohttp\n    pip install aio-apiclient[aiohttp]\n\n\n.. _usage:\n\nQuickStart\n==========\n\nGithub API (https://developer.github.com/v4/):\n\n.. code:: python\n\n    from apiclient import APIClient\n\n    # First available backend (aiohttp, httpx) will be used\n    client = APIClient('https://api.github.com', headers={\n            'Authorization': 'token OAUTH-TOKEN'\n    })\n\n    # Read information about the current repository\n    repo = await client.api.repos.klen['aio-apiclient'].get()\n    print(repo)  # dict parsed from Github Response JSON\n\n\nSlack API (https://api.slack.com/web):\n\n.. code:: python\n\n    from apiclient import APIClient\n\n    client = APIClient('https://api.github.com', headers={\n        'Authorization': 'token OAUTH-TOKEN'\n    })\n\n    # Update current user status (we don't care about this response)\n    await client.api['users.profile.set'].post(json={\n        'profile': {\n            'status_text': 'working',\n            'status_emoji': ':computer:'\n            'status_expiration': 30,\n        }\n    }, read_response_body=False)\n\n\nAnd etc\n\nUsage\n=====\n\nInitialization\n--------------\n\nThe Client initialization requires root URL for a required API.\n\n.. code:: python\n\n    from apiclient import APIClient\n\n    client = APIClient(\n\n        # Root URL for any API (required)\n        'https://api.github.com',\n\n        # Raise `client.Error` for any response with status code > 400\n        raise_for_status=True,\n\n        # Set to `False` if you only want to make a request and doesn't care about responses\n        read_response_body=True,\n\n        # Parse response's body content-type and return JSON/TEXT/Form data instead the response itself\n\n        # Set total timeout in seconds\n        timeout=10.0,\n\n        # Set backend type for making requests (apiclient.backends.BackendHTTPX,\n        # apiclient.backends.BackendAIOHTTP) by default first available would be\n        # choosen\n\n        backend_type=None,\n\n        # Default backend options to use with every request (headers, params, data, ...)\n        # ...\n\n    )\n\nApp Shutdown\n------------\n\nThe api client support graceful shutdown. Run `await client.shutdown()` when\nyou are finishing your app (not necessary).\n\n\nMiddlewares\n-----------\n\nYou are able to dinamically change request params (method, url, other backend params) using middlewares.\n\n.. code:: python\n\n    import time\n    from apiclient import APIClient\n\n    client = APIClient('https://api.github.com')\n\n    @client.middleware\n    async def insert_timestamp_header(method, url, options):\n        options.setdefault('headers', {})\n        options['headers']['X-Timestamp'] = str(time.time())\n        return method, url, options\n\n\n.. _bugtracker:\n\nBug tracker\n===========\n\nIf you have any suggestions, bug reports or\nannoyances please report them to the issue tracker\nat https://github.com/klen/aio-apiclient/issues\n\n.. _contributing:\n\nContributing\n============\n\nDevelopment of the project happens at: https://github.com/klen/aio-apiclient\n\n.. _license:\n\nLicense\n========\n\nLicensed under a `MIT license`_.\n\n\n.. _links:\n\n\n.. _klen: https://github.com/klen\n\n.. _MIT license: http://opensource.org/licenses/MIT\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Async helper to work with HTTP APIs",
    "version": "1.7.0",
    "split_keywords": [
        "apiclient",
        "muffin",
        "asyncio",
        "trio",
        "curio"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bac526cba5a4de9a9b65cf44f9cab38fd37c1e80957192a0e144d3a4477e718b",
                "md5": "fda04a4b6c70232912d023603cfdbeec",
                "sha256": "d2fd0517c12c409b2cf240d54876d2616abc800a0c9c14807b777c8e802a56ab"
            },
            "downloads": -1,
            "filename": "aio_apiclient-1.7.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "fda04a4b6c70232912d023603cfdbeec",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 9683,
            "upload_time": "2023-02-03T07:07:42",
            "upload_time_iso_8601": "2023-02-03T07:07:42.838993Z",
            "url": "https://files.pythonhosted.org/packages/ba/c5/26cba5a4de9a9b65cf44f9cab38fd37c1e80957192a0e144d3a4477e718b/aio_apiclient-1.7.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ec25fcf1dd978878398f853e34e4be7ce108cdb1d6b78e106a58c11d31896ea6",
                "md5": "6727718557a4e2087666f287ef2bdda4",
                "sha256": "726e4facf48b1389ea89908ef556f4056707a9334616f0de5dbebeffa6d9de98"
            },
            "downloads": -1,
            "filename": "aio-apiclient-1.7.0.tar.gz",
            "has_sig": false,
            "md5_digest": "6727718557a4e2087666f287ef2bdda4",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 7960,
            "upload_time": "2023-02-03T07:07:44",
            "upload_time_iso_8601": "2023-02-03T07:07:44.216352Z",
            "url": "https://files.pythonhosted.org/packages/ec/25/fcf1dd978878398f853e34e4be7ce108cdb1d6b78e106a58c11d31896ea6/aio-apiclient-1.7.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-02-03 07:07:44",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "klen",
    "github_project": "aio-apiclient",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "aio-apiclient"
}
        
Elapsed time: 0.07695s