Code Monkey home page Code Monkey logo

python-sdk's Introduction

Dapr SDK for Python

PyPI - Version PyPI - Downloads GitHub Actions Workflow Status codecov GitHub License GitHub issue custom search in repo Discord YouTube Channel Views X (formerly Twitter) Follow

Dapr is a portable, event-driven, serverless runtime for building distributed applications across cloud and edge.

Dapr SDK for Python allows you to implement the Virtual Actor model, based on the actor design pattern. This SDK can run locally, in a container and in any distributed systems environment.

This includes the following packages:

Getting started

Prerequisites

Install Dapr python sdk

  • Official package
# Install Dapr client sdk
pip3 install dapr

# Install Dapr gRPC AppCallback service extension
pip3 install dapr-ext-grpc

# Install Dapr Fast Api extension for Actor
pip3 install dapr-ext-fastapi
  • Development package
# Install Dapr client sdk
pip3 install dapr-dev

# Install Dapr gRPC AppCallback service extension
pip3 install dapr-ext-grpc-dev

# Install Dapr Fast Api extension for Actor
pip3 install dapr-ext-fastapi-dev

Note: Do not install both packages.

Try out examples

Go to Examples

Developing

Build and test

  1. Clone python-sdk
git clone https://github.com/dapr/python-sdk.git
cd python-sdk
  1. Install a project in a editable mode
pip3 install -e .
pip3 install -e ./ext/dapr-ext-grpc/
pip3 install -e ./ext/dapr-ext-fastapi/
pip3 install -e ./ext/dapr-ext-workflow/
  1. Install required packages
pip3 install -r dev-requirements.txt
  1. Run linter
tox -e flake8
  1. Run autofix
tox -e ruff
  1. Run unit-test
tox -e py311
  1. Run type check
tox -e type
  1. Run examples
tox -e examples

Documentation

Documentation is generated using Sphinx. Extensions used are mainly Napoleon (To process the Google Comment Style) and Autodocs (For automatically generating documentation). The .rst files are generated using Sphinx-Apidocs.

To generate documentation:

tox -e doc

The generated files will be found in docs/_build.

Generate gRPC Protobuf client

pip3 install -r dev-requirements.txt

./tools/regen_grpcclient.sh

Help & Feedback

Need help or have feedback on the SDK? Please open a GitHub issue or come chat with us in the #python-sdk channel of our Discord server (click here to join).

Code of Conduct

This project follows the CNCF Code of Conduct.

python-sdk's People

Contributors

aaroncrawfis avatar amanbha avatar amulyavarote avatar artursouza avatar berndverst avatar brendandburns avatar cgillum avatar chinzhiweiblank avatar dasanind avatar deepanshua avatar dependabot[bot] avatar elena-kolevska avatar hhunter-ms avatar hunter007 avatar italypaleale avatar kenthsu avatar letmerecall avatar marcduiker avatar mukundansundar avatar paulyuk avatar pkedy avatar pruthvidhodda avatar ryanlettieri avatar ryou90 avatar shivamkm07 avatar tmacam avatar wcs1only avatar wmeints avatar xaviergeerinck avatar yaron2 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-sdk's Issues

Release dapr-python v0.5.0a0

Describe the proposal

This is the release plan to ship dapr-python v0.5.0b.

  • Package name: dapr
    • python-sdk includes actor sdk implemenation with the generated proto client so that it makes sense to rename from dapr-clients to dapr
  • Package version: 0.5.0b
  • Release work items.
    • Merge features/actor to master
    • Set up CI/CD
    • Improve README.md
    • validate with dotnet-sdk
    • Release dapr-python 0.5.0a

Update pubsub example as per new proto apis

Describe the proposal

Current Pub/Sub example doesn't use update proto APIs. I propose to update the example and adapt it to the changes.

(A PR will follow shortly ๐Ÿ˜ƒ )

Support default json serializer in DaprClient and add .json helper

Describe the proposal

In the convenient layer spec, DaprClient doesn't have the default json serializer, but let users to handle JSON serialization. Like the other python pkgs, such as flask, requests, etc, DaprClient can have default json serializer to serialize and deserialize python dict type or primitive objects and provide .json() helper to DaprResponse and DataContent in AppCallback Layer. It will improve development experience instead of serializing and deserializing data object.

Unable to subscriber to a topic in pubsub-simple example

Expected Behavior

Service should spinn up with hitting dapr run --app-id python-subscriber --protocol grpc --app-port 50051 python subscriber.py

Actual Behavior

It throws following error when we try to spin up subscriber.py

== APP == Exception calling application: Protocol message ListTopicSubscriptionsResponse has no "topics" field.

== APP == Traceback (most recent call last):

== APP ==   File "/home/girish/Documents/dapr/dapr-samples/python-sdk/examples/pubsub-simple/venv/lib/python3.8/site-packages/grpc/_server.py", line 435, in _call_behavior

== APP ==     response_or_iterator = behavior(argument, context)

== APP ==   File "subscriber.py", line 21, in ListTopicSubscriptions

== APP ==     return appcallback_v1.ListTopicSubscriptionsResponse(topics=['TOPIC_A'])

== APP == ValueError: Protocol message ListTopicSubscriptionsResponse has no "topics" field.

Complete logs
dapr_logs.txt

Steps to Reproduce the Problem

Run dapr run --app-id python-subscriber --protocol grpc --app-port 50051 python subscriber.py from examples/pubsub-simple

Settings & configurations

  • using standalone dapr
  • tried with both dapr & dapr-dev
  • CLI version: 0.8.0
  • Runtime version: 0.8.0

[Proposal] Using Dapr and Python-sdk for ML/DL model deployment

Describe the proposal

The ultimate goal of ML and DL model development is to integrate with the production services. Typically, ML and DL engineers focus on model development rather than how they will integrate model with their services.

Many articles and tutorials introduces how to serve the model with Flask. Once they have Flask service with their model to their production, the backend and frontend services need to implement client code to talk to model server.

Dapr and Python-sdk will be able to resolve this problem easier. So ML engineer creates micro service and deploy it to production cluster without the knowledge of http restful api server and microservice deployment. Backend engineer can use service invocation api to use the model without model server client implementation.

Add a Pubsub Example

Proposal

Add an example (similar to invoke-simple ) showing pubsub pattern.

Why to add?

Pubsub is a very essential feature and it's hard to find a template to make a subscriber.

Actor Implementation

I currently do not see a way to implement actor methods, is this already supported in the Python SDK? ๐Ÿ˜Š

Sphinx Auto-generation of Documentation

Describe the proposal

Sphinx can be used to generate documentation automatically with the autodoc extension. Napoleon extension can be used to process the Google comment style.

Cannot import module "daprclient" in `daprclient_pb2_grpc.py`

When trying to import daprclient_pb2_grpc.py to access the OnInvoke method, an error is thrown. Without this, a correct example utilizing the OnInvoke method can not be created, disallowing the E2E communication of 2 RPC microservices (client and server).

It seems that on the source repo the following proto files are found:

It might be that there is some wrong packaging behavior happening?

Expected Behavior

This should work to allow the creation of the OnInvoke method.

Actual Behavior

== APP == Traceback (most recent call last):
== APP ==   File "server.py", line 7, in <module>
== APP ==     from dapr import daprclient_pb2_grpc as servicesClient
== APP ==   File "C:\Python37\lib\site-packages\dapr\daprclient_pb2_grpc.py", line 4, in <module>
== APP ==     from daprclient import daprclient_pb2 as daprclient_dot_daprclient__pb2
== APP == ModuleNotFoundError: No module named 'daprclient'

Steps to Reproduce the Problem

  1. Create a new Python file (e.g. server.py)
  2. Add line from dapr import daprclient_pb2_grpc as services
  3. Run the application (e.g. dapr run --app-id python-grpc --port 3500 --protocol grpc --grpc-port 50001 python server.py)

Example - Invoke/OnInvoke Method

Describe the proposal

Adding an example on how to utilize the OnInvoke method from the proto bindings. This example helps users on how to create a gRPC server that can listen on direct method invocations.

Add support for async gRPC in Dapr SDK

Describe the proposal

grpc_asyncio is still WIP. We may need to support it later when grpc_asyncio is stable.
https://grpc.github.io/grpc/python/grpc_asyncio.html

Update: grpc_asyncio is now available, however we should publish an asynchronous Dapr Python SDK as a separate SDK, or at least sub package - like dapr.aio (from dapr.aio.clients import DaprClient)

There were concerns from several users about the performance overhead of calling asynchronous methods and running them in a synchronous context, so simply switching over to grpc.aio is not an option unfortunately.

Please mark Dapr-dev Python >= 3.7 instead of 3.8

Describe the proposal

I would like to see Python >= 3.7 supported instead of 3.8 (which is cutting edge), seeing that a lot of libraries are still depending on 3.7 at the moment.

Note: Currently I manually clone and install it locally and it's working on Python 3.7 for me

Add Secret api to convenient layer

Describe the proposal

Add Secrets apis to convenient layer.

Parent epic : #67

  • Implementation
  • Unit-tests
  • Documentation in code
  • update or add examples

Allow to pass W3C trace headers to Dapr Api calls

Allow to pass W3C trace header(traceparent) or grpc-trace-bin to Dapr Api call.

0.8.0 supports traceparent and grpc-trace-bin. Python-sdk needs the way to pass traceparent for http or grpc-trace-bin metadata for grpc.

RELEASE NOTE: ADD W3C trace headers to Dapr API calls.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.