Skip to main content

REST-CLIENT

Tests

Setup a client in minutes


Installation

pip install rapid-rest-client

Usage

There are multiple options to auto-create a client. Here's using a swagger definition:

from rest_client.base import BaseUrlConfig, SwaggerApiConfiguration, Client

petstore_endpoint_config: BaseUrlConfig = BaseUrlConfig('https://petstore.swagger.io/v2/')

@SwaggerApiConfiguration(url='https://petstore.swagger.io/v2/swagger.json', base_url_config=petstore_endpoint_config)
class SwaggerUrlConfiguredClient(Client):
    pass

swagger_url_configured_client = SwaggerUrlConfiguredClient()

# Client now has all paths available, as defined in the json file at url

r = swagger_url_configured_client.find_pets_by_status(status='pending')
print(r)

You can also pass the swagger definition as a dict:

@SwaggerApiConfiguration(definition={<swagger dict>}, base_url_config=petstore_endpoint_config)

Manually creating a client:

from rest_client.base import BaseUrlConfig, ApiConfiguration, RequestConfig, Client

endpoint_config: BaseUrlConfig = BaseUrlConfig('https://reqres.in/api/', 'https://sandbox.reqres.in/api/')

@ApiConfiguration(endpoints=[
    RequestConfig('users', 'list_users'),
    RequestConfig('users/{}', 'get_user'),
    RequestConfig('register', 'register_user', 'POST')
], base_url_config=endpoint_config)
class ExampleClient(Client):
    pass

This makes these methods available on ExampleClient

  • list_users
  • get_user
  • register_user
client = ExampleClient()
list_users_response = client.list_users()
get_user_response = client.get_user(3)
register_user_response = client.register_user(email="eve.holt@reqres.in", password="pistol")

If you want to customize a method, you can simply add methods to a client. Use the endpoint decorator to do that:

from rest_client.base import endpoint, Client

class ExampleClient(Client):
    @endpoint('users', 'list_users')
    def list_users(self, **kwargs):
        return self._request(kwargs)

You can also create the client from json, or a dict:

from rest_client.base import DictApiConfiguration, BaseUrlConfig, Client

endpoint_config: BaseUrlConfig = BaseUrlConfig('https://reqres.in/api/')

@DictApiConfiguration(endpoints=[{
    'path': 'users',
    'name': 'list_users',
}], base_url_config=endpoint_config)
class MyClient(Client):
    pass

Authentication

You can pass custom authentication through the authentication_handler property. Authentication handlers should extend AuthBase from requests.auth

For example:

from rest_client.base import BaseUrlConfig, ApiConfiguration, RequestConfig, Client, BearerTokenAuth

auth_endpoint_config: BaseUrlConfig = BaseUrlConfig('https://gorest.co.in/public/v1/')

@ApiConfiguration(
    endpoints=[
        RequestConfig('users', 'register_user', 'POST'),
    ],
    base_url_config=auth_endpoint_config)
class AuthClient(Client):
    pass

auth_client = AuthClient(
    authentication_handler=BearerTokenAuth('token')
)

Please note:

This is a work in progress and completely new. Contributions are very welcome.


Quality gate

Maintainability Rating Reliability Rating Coverage

Bugs Code Smells Technical Debt

Security Rating Lines of Code Duplicated Lines (%)

Metadata

Release files for rapid-rest-client 0.0.5

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

Source distribution (sdist)

Source distribution for rapid-rest-client 0.0.5
File Size Uploaded
rapid_rest_client-0.0.5.tar.gz 6.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for rapid-rest-client 0.0.5
File Interpreter ABI Platform
rapid_rest_client-0.0.5-py3-none-any.whl Python 3 none any Details

Total release size: 16.0 kB

Release files / rapid_rest_client-0.0.5.tar.gz

Download URL rapid_rest_client-0.0.5.tar.gz
Size 6.9 kB
Tags Source
SHA-256 checksum
How to use checksums
99354a634c032d3d98c3b15bde74ba6e92b0c36043b8a8ef2dee7f3033bc0520
BLAKE2b-256 checksum
How to use checksums
cf3c20e13d358a410d0c7a2c8cfc4418b5429394f22ffc2cd571264768c77b4e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release files / rapid_rest_client-0.0.5-py3-none-any.whl

Download URL rapid_rest_client-0.0.5-py3-none-any.whl
Size 9.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
293313535c20d06b4e2f313b4b5df902aaa2441acef5d93ee8d2f0a72b19d021
BLAKE2b-256 checksum
How to use checksums
97fd3a67eb151c5a0ff951f6fcf7008ed382eaed21b973fbb77691415bb7c839
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release history Release notifications | RSS feed

This release

0.0.5 This release

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

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