Skip to content

http/python: Add simple HTTP GET example with FastAPI and Uvicorn#37

Merged
ianmcook merged 2 commits into
apache:mainfrom
ianmcook:fastapi
Sep 18, 2024
Merged

http/python: Add simple HTTP GET example with FastAPI and Uvicorn#37
ianmcook merged 2 commits into
apache:mainfrom
ianmcook:fastapi

Conversation

@ianmcook

Copy link
Copy Markdown
Member

Closes apache/arrow#40869.

Supercedes #27

Co-authored-by: Arun Pa <arunppsg@gmail.com>
Comment thread http/get_simple/python/server/fastapi_uvicorn/server.py Outdated
@ianmcook

Copy link
Copy Markdown
Member Author

Note for posterity:

To adapt this to work with just plain Starlette (no FastAPI):

  1. Replace the FastAPI imports with:

    from starlette.applications import Starlette
    from starlette.responses import StreamingResponse
    from starlette.routing import Route
  2. Replace app = FastAPI() and everything below that with:

    def main(request):
        return StreamingResponse(
            generate_bytes(schema, batches),
            media_type="application/vnd.apache.arrow.stream"
        )
    
    app = Starlette(routes=[Route("/", endpoint=main)])

@ianmcook

Copy link
Copy Markdown
Member Author

Tested and confirmed works with various client examples.

@ianmcook ianmcook merged commit b3b4b23 into apache:main Sep 18, 2024
@ianmcook ianmcook deleted the fastapi branch September 18, 2024 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Python] Create simple HTTP server example using FastAPI

3 participants