"Simple Interface to easily switch to dapr APIs from requests and aiohttp"
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 addtional 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
test_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=test_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
Hashes for dapr_api_wrapper-1.2.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 346598fa4b368916f9f4e011033f7ac2618286497b793f158bd52c74b8d1ec3c |
|
MD5 | a2fd86570b29bd5751d9e0a7e9d87395 |
|
BLAKE2b-256 | ab3954c2a6a5a50263ce18387c88d441cd09554b64fcec92ccf46440f7e8d13b |