Skip to content

Conversation

@sidgaikwad
Copy link
Contributor

๐Ÿ”„ Migration: PyGitHub โ†’ httpx GitHub Client

๐Ÿ“Œ Overview

This project has migrated from using PyGitHub (a Python wrapper for the GitHub REST API) to a fully async httpx-based GitHub client.

The new implementation improves performance, flexibility, and reliability while keeping the same method signatures and naming conventions (repo_name, file_path_to_change, etc.), ensuring smooth migration.


โœ… Key Changes

  • Replaced PyGitHub usage with httpx.AsyncClient
  • Full async support (no run_in_executor wrapping)
  • Unified method signatures for consistency
  • Implemented retry with exponential backoff for API calls
  • Clearer and more descriptive error handling
  • Explicit base64 encoding/decoding for file contents

๐Ÿš€ Advantages of httpx over PyGitHub

1. True Async Support

  • PyGitHub โ†’ synchronous, required wrapping with asyncio.run_in_executor
  • httpx โ†’ natively asynchronous, leverages asyncio directly

2. Performance

  • Connection pooling & keep-alive enabled by default
  • Scales better when running multiple repo operations concurrently

3. Flexibility

  • Full control over GitHub REST API endpoints
  • Not limited by PyGitHub abstractions
  • Easier to extend for GraphQL API support in the future

4. Robust Error Handling

  • Exponential backoff + jitter for transient errors (502, 503, 504)
  • Handles GitHubโ€™s rate limiting (Retry-After headers respected)
  • Clearer error messages for debugging

5. Reduced Dependencies

  • Removes PyGitHub dependency
  • Relies only on httpx and Python stdlib

๐Ÿ› ๏ธ API Usage (Examples)

Create Issue

issue_number, error = await github_client.create_issue(
    title="Bug Report",
    body="Steps to reproduce...",
    owner="my-org",
    repo_name="my-repo",
)

Create PR with File Changes

pr_number, error = await github_client.create_pr_with_file_changes(
    title="Update config",
    body="This PR updates the config file.",
    owner="my-org",
    repo_name="my-repo",
    base_branch="main",
    head_branch="update-config",
    file_path_to_change="config/settings.yml",
    file_content_to_change="new content here",
    commit_message="Update config settings"
)

Get File Content

lines, error = await github_client.get_file_content(
    owner="my-org",
    repo_name="my-repo",
    file_path="README.md",
    ref="main",
)

๐Ÿ”ฎ Next Steps

  • Add more test coverage for retry/backoff behavior
  • Explore GitHub GraphQL API for richer queries
  • Extend client for GitHub App / OAuth authentication

๐Ÿ“– Conclusion

By migrating to httpx, the GitHub client is now faster, async-native, and more resilient.
This positions us for better scalability and easier future extensions, while maintaining backward compatibility with the previous PyGitHub-based API.

Fixes: #110

@sidgaikwad sidgaikwad requested a review from a team as a code owner August 27, 2025 15:38
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.

[Enhancement] Make GitHub call truly async

1 participant