Requests-like Interface to easily switch to dapr APIs from requests library
Project description
Dapr Api Wrapper
This is a simple Interface built over Microsoft Dapr APIs for easy transition from libraries like requests and aiohttp to dapr's grpc interface without additional changes in code.
Requirements
- Kubernetes cluster (eg. Azure Kubernetes)
- Dapr Setup in Kubernetes
Setup
Step:1
Copy the contents of configuration yml from dapr_api_wrapper > setup > setup.yml
Step:2
Paste them in a new dapr_setup.yml file and add references to passwords (recommended) or passwords directly. Change namespace if required.
Step:3
Apply changes to your kubernetes cluster by running: kubectl apply -f path/to/your/dapr_setup.yml
Step:4
In your kubernetes pod deployment.yml configuration add dapr annotations as referenced here.
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: myawesome-svc
name: myawesome-svc-deployment
spec:
replicas: 1
selector:
matchLabels:
app: myawesome-svc
# Add the below lines
# Remove '#' to uncomment any annotation
template:
metadata:
annotations:
dapr.io/app-id: myawesome-svc
dapr.io/app-port: "<myawesome-svc-port>"
dapr.io/app-protocol: http # http | grpc
dapr.io/config: appconfig
# dapr.io/enable-metrics: "true"
# dapr.io/enable-profiling: "true" # Setting this paramater to true starts the Dapr profiling server on port 7777
dapr.io/enabled: "true"
# dapr.io/http-max-request-size: 64 # Increasing max size of request body http and grpc servers parameter in MB to handle uploading of big files. Default is 4 MB
# dapr.io/log-as-json: "false"
dapr.io/log-level: debug # info | warn | error
# dapr.io/metrics-port: "9090"
# dapr.io/sidecar-cpu-limit: 1
# dapr.io/sidecar-memory-limit: 500Mi
labels:
app: myawesome-svc
redis-client: "true"
# Add the above lines
# Further configuration
spec:
containers:
Understanding the request
Get the request arguments from the docstring of below mentioned class.
from dapr_api_wrapper.requests import DaprRequest
API Usage
from dapr_api_wrapper import requests as dapr_requests
from datetime import datetime
request_body = {
"id": "12345",
"api_key": "1234567",
"updated_at": str(datetime.now()),
"num": 1234567,
"is_auth": True,
}
resp = dapr_requests.post(
app_id="myawesome-svc",
url_path="http://myawesome-svc-svc/test",
data=request_body,
content_type="application/json",
headers={"key1": "value1"},
http_query_params={"querykey1": "queryvalue1"},
)
resp_json = resp.json()
resp_text = resp.text
resp_bytes = resp.bytes()
print (f"\n{resp_json = }\n{resp_text = }\n{resp_bytes = }", flush=True)
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dapr_api_wrapper-1.2.8.tar.gz.
File metadata
- Download URL: dapr_api_wrapper-1.2.8.tar.gz
- Upload date:
- Size: 8.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0903808de1a0ef15843e0d5e84847d30f1eb425f7124461e85c2aedd5d632169
|
|
| MD5 |
1c94e86d443fb984c0c494eeac2ab19a
|
|
| BLAKE2b-256 |
e5b6ef872d2f2d9f025edc15dd1e1634fef8923ea5975e17dd39f29c19295445
|
File details
Details for the file dapr_api_wrapper-1.2.8-py3-none-any.whl.
File metadata
- Download URL: dapr_api_wrapper-1.2.8-py3-none-any.whl
- Upload date:
- Size: 10.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a6cfa259e8c892e816ca6a2df122c29da66a007de6aff42a7d6b01f169926ca7
|
|
| MD5 |
f61c80ec70cd4d3dc8c68d3c5272af40
|
|
| BLAKE2b-256 |
33cb8a3e526bc00b92c356c6f383fc5c6d54e5b89b9353bdaea77106f4c06be6
|