Base API Connector
Helps create a simple API Connector where all you have to do is define the resources and possible commands.
Instructions
Using the Module
First import the GenericAPIConnector class:
from base_api_connector import GenericAPIConnector
Then, define a base_api_url and resource fields like this:
class ImplementedAPIConnector(GenericAPIConnector):
base_api_url = 'http://127.0.0.1:8000/notes-backend/'
reports = APIResource(('create', 'retrieve', 'update'))
users = APIResource('all')
That will generate the following attributes when you use the class:
conn = ImplementedAPIConnector()
conn.reports.create(data)
conn.reports.retrieve(pk)
conn.reports update(pk, data)
conn.users.list()
conn.users.create(data)
conn.users.retrieve(pk)
conn.users.update(pk, data)
conn.users.delete(pk)
Asyncio
You can tell tell your resource fields that they should be accessed with asyncio per default:
class ImplementedAPIConnector(GenericAPIConnector):
# ...
users = APIResource('all', is_async=True)
and then use it in an async metho as follows:
async def create_user(user):
r = await conn.user.create(user)
data = await r.json()
# ...
Alternatively, you can change switch to async in-line as well:
# ...
r = await conn.reports(is_async=True).list()
# ...
or the other way around:
r = conn.user(is_async=False).list()
Using The Returned Object
The methods of GenericAPIConnector return a regular Response object from the requests module. See requests Documentation for Response for more details.
Using AsDictObject (WIP)
If you want to define how a resource looks only once, import AsDictObject:
import datetime
from base_api_connecotr import AsDictObject
class CreateUsersResourceObject(AsDictObject):
name = None # None will not pass the field in the request
created = datetime.datetime.now # use methods to set defaults like this
created_for_app = 'readme_example'
And then use it like this:
user = CreateUsersResourceObject():
user.name = 'readme user'
conn.users.create(user)
Metadata
Release files for base-api-connector 0.3.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| base_api_connector-0.3.1.1-py3-none-any.whl | Python 3 | none | any | Details for base_api_connector-0.3.1.1-py3-none-any.whl |
Release files / base_api_connector-0.3.1.1-py3-none-any.whl
| Download URL | base_api_connector-0.3.1.1-py3-none-any.whl |
|---|---|
| Size | 10.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
693eeee452d9383b651f9ddfc79f44dd0ac40da5877b29a0783cb11260b849a3
|
|
BLAKE2b-256 checksum How to use checksums |
bc3a9caaa4cde4df756585c74f2e914a40703ceb482494b7a16ae1ad7c3637bf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.0
|
Security for base-api-connector 0.3.1.1
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.