dispatchrun / dispatch-py

Python package to develop applications with Dispatch.
https://pypi.org/project/dispatch-py/
Apache License 2.0
54 stars 3 forks source link

Endpoint #135

Closed chriso closed 6 months ago

chriso commented 6 months ago

This PR changes the import scheme so that the construction of local and remote endpoints is clearer.

For remote endpoints:

from dispatch.remote import Endpoint

remote = Endpoint(url)

@remote.function
def my_remote_func(): ...

For local endpoints (e.g. using FastAPI):

from fastapi import FastAPI
from dispatch.fastapi import Endpoint

app = FastAPI()
dispatch = Endpoint(app)

@dispatch.function
def my_local_func(): ...

Previously you had from dispatch.fastapi import Dispatch for local endpoints, and from dispatch import Registry for remote endpoints (#134).

With this PR we avoid using the ambiguous Dispatch and Registry names, and the ambiguous top-level namespace (from dispatch import $thing).

I've maintained backward compatibility by creating a dispatch.fastapi.{Dispatch => Endpoint} alias (so from dispatch.fastapi import Dispatch continues to work).