speedyapi
An easy-to-use Python module for creating API.
Built on Flask / Async Flask with features for easily creating API endpoints
Features:
- Parameter Parsing and Checking
- API Authentication
- Rate Limiting (user, address, global)
- In-depth Endpoint Testing (Write tests to be run that confirm endpoints act as intended)
- Automatic OpenAPI
swagger.jsonGeneration (with access to full specification) - Common JSON Response Formatting
Installation
Simply run pip install speedyapi. The PyPI package is at https://pypi.org/project/speedyapi/
Dependencies
Example Usage
from speedyapi import API, QueryParameter, PathParameter, respond, request, Test, types
from speedyapi.swagger_objects import InfoObject, XLogoObject
info = InfoObject(title="Example API", version="1.0.1")
app = API(__name__, info=info)
app.swagger.info.logo = XLogoObject(url="")
app.swagger.info.description = "# Introduction\nThis is an example API for the speedyapi python module."
@app.authentication(apikey_required=True, description="Example apikey: `CorrectApikey`")
def auth():
return "allowed" if request.apikey == "CorrectApikey" else None
@app.endpoint(path="/maths/<method>", method="GET", authentication="allowed", name="Simple Maths", description="Simple operations.")
@app.limits(user_limits=["10/min"], ip_limits=["30/min"], global_limits=["5000/5 min"])
@app.tests(Test(url="/maths/multiply?a=3&b=5", headers={"Apikey": "CorrectApikey"}, expected_status_code=200, checks=[lambda x: x["result"] == 15]),
Test(url="/maths/multiply?a=3&b=5", headers={"Apikey": "WrongApikey"}, expected_status_code=403),
Test(url="/maths/modulo?a=3&b=5", headers={"Apikey": "CorrectApikey"}, expected_status_code=422),
Test(url="/maths/multiply?a=3&b=5", expected_status_code=400))
@app.parameters(PathParameter(name="method", options=["multiply", "divide", "add", "subtract"], default="add", description="Choose operation."),
QueryParameter(name="a", type=types.Number, required=True, description="First number to use."),
QueryParameter(name="b", type=types.Number, required=True, description="Second number to use."))
def simple_maths_endpoint(method, a, b):
methods = {"multiply": lambda x, y: x * y, "divide": lambda x, y: x / y, "add": lambda x, y: x + y, "subtract": lambda x, y: x - y}
return respond.json({"result": methods[method](a, b), "method": method, "authentication": request.authentication})
if __name__ == "__main__":
app.run(host="0.0.0.0", port=80, tests=True, threaded=True)
------------------------------------------------------------------------------------------
* Test on path `/maths/multiply - - GET` returned correct status code 200 [Time: 2.12s] - - {"success": true, "result": 15, "method": "multiply", "authentication": "allowed"}
* Test on path `/maths/multiply - - GET` Success [Time: 2.12s] - - {"success": true, "result": 15, "method": "multiply", "authentication": "allowed"}
* Test on path `/maths/modulo - - GET` returned correct status code 422 [Time: 2.12s] - - {"success": false, "cause": "Malformed [method]"}
* Test on path `/maths/multiply - - GET` returned correct status code 400 [Time: 2.12s] - - {"success": false, "cause": "Missing one or more fields [key]"}
* Test on path `/maths/multiply - - GET` returned correct status code 403 [Time: 2.12s] - - {"success": false, "cause": "Access is forbidden, usually due to an invalid API key being used."}
* Tests Completed - - (Success: 5/5) - [Time: 2.13s]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* API Ready - - [Running on: http://0.0.0.0:80/] - - (Press CTRL+C to quit!)
------------------------------------------------------------------------------------------
Metadata
Release files for speedyapi 1.0.11
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| speedyapi-1.0.11.tar.gz | 43.3 kB | Without provenance | Details for speedyapi-1.0.11.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| speedyapi-1.0.11-py3-none-any.whl | Python 3 | none | any | Details for speedyapi-1.0.11-py3-none-any.whl |
Total release size: 89.3 kB
Release files / speedyapi-1.0.11.tar.gz
| Download URL | speedyapi-1.0.11.tar.gz |
|---|---|
| Size | 43.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
baee7ec80e3592ff1646dfc0aa38e60ba640809ad4d365070d2796201a96724f
|
|
BLAKE2b-256 checksum How to use checksums |
7b6d44ffb90b0a5e39348b68bccfbf64ffa787693704139ed9514adab719f04e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.8.0
|
Release files / speedyapi-1.0.11-py3-none-any.whl
| Download URL | speedyapi-1.0.11-py3-none-any.whl |
|---|---|
| Size | 46.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6fcb06d29c74d0780e37718eddc02da9ae0f7fe13255444f3943424ec590517b
|
|
BLAKE2b-256 checksum How to use checksums |
d207460b6fe71a52ee97ac78e2ffd1fcaad9a959f9215f1ad779e835c687488c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.8.0
|
Security for speedyapi 1.0.11
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.