Easily create maintainable API clients.
Project description
BaseAPI
Easily create maintainable API clients.
Rationale
Building other Python based API clients I found that there was a tendency to end up with a "mega-class", containing most of the definitions of my API. BaseAPI tries to keep unrelated API concepts separate, hopefully making for an easier maintenance experience.
Installation
PyPi is the easiest way to install:
pip install base-api
Usage
Creating a client
Normally the Client
class is inherited to create your own client
class:
from baseapi import Client
class MyClient(Client):
DEFAULT_URL = 'https://my-api.com'
Here we've set our default API URL. This can also be set during the creation of the client:
client = MyClient(url='https://localhost')
Creating APIs
To populate your client with functions to access your API use individual API classes. These reflect an isolated part of your overall API.
As an example, you may have an authorization component to your API. To
add authorization to your client library, you may create a file called
auth.py
:
from baseapi.apis import GraphqlApi
class AuthApi(GraphqlApi):
@GraphqlAPI.expose_method
def login(self, username, password):
# TODO
pass
@GraphqlAPI.expose_method
def logout(self):
# TODO
pass
Once you have this slice of your API ready, you can add it to your client by specifying it during the client class definition:
from baseapi import Client
class MyClient(Client):
DEFAULT_URL = 'https://my-api.com'
DEFAULT_APIS = (
'auth',
)
In this case, auth.py
must be placed in your PYTHONPATH
, most
likely alongside your client class file.
TODO: More to come...
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
File details
Details for the file base-api-0.0.2.tar.gz
.
File metadata
- Download URL: base-api-0.0.2.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/43.0.0 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.8.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c659448f9e3e231ca1f43bd36300d61272a637002c487a6b2ce245ee7cc14900 |
|
MD5 | 5816174e29c4ed73065296afde27df0c |
|
BLAKE2b-256 | c5d50acb8d77f32cf58a7be950d470ee4d48d1efd688d1092114964fd43b5fe7 |