Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example usage of httpx #6325

Merged
merged 9 commits into from
Jan 22, 2025
Merged

Example usage of httpx #6325

merged 9 commits into from
Jan 22, 2025

Conversation

tofarr
Copy link
Collaborator

@tofarr tofarr commented Jan 16, 2025

End-user friendly description of the problem this fixes or functionality that this introduces

This PR updates the GitHub API integration to use httpx instead of requests for making HTTP requests. This change improves the async support in our GitHub routes, making them more efficient and performant.

  • Include this change in the Release Notes. If checked, you must provide an end-user friendly description for your change below

Improved performance of GitHub API integration by using modern async HTTP client.


Give a summary of what the PR does, explaining any non-trivial design decisions

This PR replaces the synchronous requests library with the asynchronous httpx library in our GitHub API integration routes. Key changes include:

  1. Removed the need for call_sync_from_async by using native async HTTP calls
  2. Better resource management using async context managers
  3. More efficient handling of HTTP responses
  4. Maintained existing functionality while improving performance

Link of any specific issues this addresses

N/A


To run this PR locally, use the following command:

docker run -it --rm   -p 3000:3000   -v /var/run/docker.sock:/var/run/docker.sock   --add-host host.docker.internal:host-gateway   -e SANDBOX_RUNTIME_CONTAINER_IMAGE=docker.all-hands.dev/all-hands-ai/runtime:5c644ce-nikolaik   --name openhands-app-5c644ce   docker.all-hands.dev/all-hands-ai/openhands:5c644ce

@tofarr tofarr marked this pull request as ready for review January 17, 2025 22:55
async with httpx.AsyncClient() as client:
response = await client.get('https://api.github.com/user', headers=headers)
response.raise_for_status() # Raise an error for HTTP codes >= 400
json_response = JSONResponse(content=response.json())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

constructing a JSONResponse here is odd, but it looks like we were already doing it...

@tofarr tofarr enabled auto-merge (squash) January 22, 2025 15:47
@tofarr tofarr merged commit 1337d03 into main Jan 22, 2025
16 checks passed
@tofarr tofarr deleted the fix-httpx-example branch January 22, 2025 16:06
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.

2 participants