Convert Figma logo to code with AI

sigmavirus24 logogithub3.py

Hi, I'm a library for interacting with GItHub's REST API in a convenient and ergonomic way. I work on Python 3.6+.

1,203
401
1,203
64

Top Related Projects

Typed interactions with the GitHub API v3

GitPython is a python library used to interact with Git repositories.

1,606

Python bindings for libgit2

A Python SOAP client

Quick Overview

GitHub3.py is a comprehensive Python library for interacting with the GitHub API. It provides a Pythonic interface to access and manipulate GitHub resources, including repositories, issues, pull requests, and more. The library aims to cover most of the GitHub API v3 endpoints while maintaining a user-friendly and intuitive design.

Pros

  • Extensive coverage of GitHub API endpoints
  • Well-documented with clear examples and API references
  • Supports both synchronous and asynchronous operations
  • Actively maintained with regular updates and bug fixes

Cons

  • Learning curve for new users due to the extensive API coverage
  • Some advanced features may require deeper understanding of GitHub API concepts
  • Occasional breaking changes between major versions
  • Limited support for GitHub Enterprise-specific features

Code Examples

  1. Authenticating and fetching user information:
from github3 import login

gh = login(token='your_access_token')
user = gh.me()
print(f"Logged in as: {user.name}")
print(f"Public repos: {user.public_repos_count}")
  1. Creating an issue in a repository:
repo = gh.repository('owner', 'repo_name')
issue = repo.create_issue(
    title="New feature request",
    body="Please add support for X",
    labels=['enhancement']
)
print(f"Issue created: {issue.html_url}")
  1. Listing pull requests for a repository:
repo = gh.repository('owner', 'repo_name')
for pr in repo.pull_requests(state='open'):
    print(f"#{pr.number}: {pr.title} by {pr.user.login}")
  1. Fetching repository statistics:
repo = gh.repository('owner', 'repo_name')
stats = repo.statistics_commit_activity()
for week in stats:
    print(f"Week of {week.week}: {week.total} commits")

Getting Started

To get started with GitHub3.py, follow these steps:

  1. Install the library using pip:

    pip install github3.py
    
  2. Import the library and authenticate:

    from github3 import login
    
    # Authenticate using a personal access token
    gh = login(token='your_access_token')
    
    # Or authenticate using username and password (not recommended)
    # gh = login('username', 'password')
    
  3. Start using the library to interact with GitHub:

    # Get information about the authenticated user
    user = gh.me()
    print(f"Logged in as: {user.login}")
    
    # Fetch a repository
    repo = gh.repository('owner', 'repo_name')
    print(f"Repository: {repo.name}")
    print(f"Stars: {repo.stargazers_count}")
    

For more detailed information and advanced usage, refer to the official documentation at https://github3py.readthedocs.io/.

Competitor Comparisons

Typed interactions with the GitHub API v3

Pros of PyGithub

  • More comprehensive API coverage, including newer GitHub features
  • Larger and more active community, resulting in faster updates and bug fixes
  • Better documentation and examples for easier onboarding

Cons of PyGithub

  • Slightly more complex API structure, which may require a steeper learning curve
  • Larger package size, potentially impacting installation and load times
  • Less focus on maintaining backwards compatibility across versions

Code Comparison

PyGithub:

from github import Github

g = Github("access_token")
repo = g.get_repo("PyGithub/PyGithub")
issue = repo.create_issue(title="New issue", body="This is the body")

github3.py:

from github3 import login

gh = login(token="access_token")
repo = gh.repository("sigmavirus24", "github3.py")
issue = repo.create_issue(title="New issue", body="This is the body")

Both libraries offer similar functionality for basic GitHub operations. PyGithub tends to use more object-oriented approaches, while github3.py often employs a more functional style. The choice between the two may depend on personal preference, specific project requirements, and the need for certain GitHub API features.

GitPython is a python library used to interact with Git repositories.

Pros of GitPython

  • Focuses on local Git operations, providing more comprehensive Git functionality
  • Allows direct interaction with Git repositories on the filesystem
  • Supports a wider range of Git operations, including branching, merging, and commit history manipulation

Cons of GitPython

  • Limited to local Git operations, lacking direct GitHub API integration
  • May require more setup and configuration for GitHub-specific tasks
  • Potentially steeper learning curve for developers primarily interested in GitHub interactions

Code Comparison

GitPython (local repository operations):

from git import Repo

repo = Repo("/path/to/repo")
repo.git.add(".")
repo.index.commit("Commit message")
origin = repo.remote("origin")
origin.push()

github3.py (GitHub API interactions):

from github3 import login

gh = login(token="your_access_token")
repo = gh.repository("owner", "repo")
repo.create_file("path/to/file", "Commit message", "File content")

GitPython excels at local Git operations, while github3.py is tailored for GitHub API interactions. The choice between them depends on whether you need to work with local repositories or interact with GitHub's web-based features.

1,606

Python bindings for libgit2

Pros of pygit2

  • Direct access to Git internals, allowing low-level operations
  • Faster performance for certain Git operations
  • Supports both local and remote repository operations

Cons of pygit2

  • Steeper learning curve due to lower-level API
  • Less focused on GitHub-specific features
  • Requires more manual handling of authentication and API interactions

Code Comparison

pygit2:

repo = pygit2.Repository('/path/to/repo')
commit = repo.revparse_single('HEAD')
tree = commit.tree

github3.py:

gh = github3.login(username, password)
repo = gh.repository('owner', 'repo')
branch = repo.branch('main')

Summary

pygit2 is a lower-level Git library offering direct access to Git internals and better performance for certain operations. It's suitable for projects requiring fine-grained control over Git repositories. github3.py, on the other hand, is specifically designed for interacting with GitHub's API, providing a higher-level interface for GitHub-specific operations. The choice between the two depends on whether you need direct Git manipulation or GitHub-specific functionality.

A Python SOAP client

Pros of python-zeep

  • Specialized for SOAP/WSDL interactions, offering robust support for complex web services
  • Extensive documentation and examples for various SOAP scenarios
  • Active development with frequent updates and bug fixes

Cons of python-zeep

  • Limited to SOAP/WSDL, not a general-purpose API client like github3.py
  • Steeper learning curve for developers unfamiliar with SOAP protocols
  • May have more dependencies and complexity for simple use cases

Code Comparison

python-zeep example:

from zeep import Client

client = Client('http://www.webservicex.net/ConvertSpeed.asmx?WSDL')
result = client.service.ConvertSpeed(100, 'kilometersPerhour', 'milesPerhour')
print(result)

github3.py example:

from github3 import login

gh = login('username', 'password')
repo = gh.repository('owner', 'repo')
issue = repo.create_issue('Issue Title', 'Issue Body')
print(issue.number)

Both libraries provide clean, Pythonic interfaces for their respective domains. python-zeep focuses on SOAP operations, while github3.py offers a more general-purpose GitHub API client. The choice between them depends on the specific requirements of your project.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

.. image:: https://raw.github.com/sigmavirus24/github3.py/master/docs/img/gh3-logo.png

github3.py is a comprehensive, actively developed, and extraordinarily stable wrapper around the GitHub API (v3).

Note: This library currently works with Python 3.7+ or pypy3. For older versions, please use version 1.3.0.

Installation

::

$ pip install github3.py

Dependencies

  • requests_
  • uritemplate_
  • python-dateutil_
  • PyJWT_

.. _requests: https://github.com/kennethreitz/requests .. _uritemplate: https://github.com/sigmavirus24/uritemplate .. _python-dateutil: https://github.com/dateutil/dateutil .. _PyJWT: https://github.com/jpadilla/pyjwt

Contributing

Please read the CONTRIBUTING_ document.

.. _CONTRIBUTING: https://github.com/sigmavirus24/github3.py/blob/master/CONTRIBUTING.rst

Testing


You can run ``pip install -e .[dev]`` to install the following before testing or
simply ``make test-deps``. It is suggested you do this in a virtual environment.
These need to be installed for the tests to run.

- betamax_
- coverage_ by Ned Batchelder

.. _betamax: https://github.com/sigmavirus24/betamax
.. _coverage: http://nedbatchelder.com/code/coverage/

Build status

You can find build statuses for different environments.

  • Github_

.. _Github: https://github.com/sigmavirus24/github3.py/actions

License

Modified BSD license_

.. _license: https://github.com/sigmavirus24/github3.py/blob/master/LICENSE

Examples

See the docs_ for more examples.

.. _docs: https://github3.readthedocs.io/en/latest/index.html#more-examples

Testing


Install the dependencies from requirements.txt e.g.:

::

    make tests

Author
------

Ian Stapleton Cordasco (sigmavirus24_)

.. _sigmavirus24: https://github.com/sigmavirus24

Contact Options
---------------

- Feel free to use the `github3.py`_ tag on Stack Overflow for any questions
  you may have.
- If you dislike Stack Overflow, it is preferred that you use Github
  discussions (https://github.com/sigmavirus24/github3.py/discussions).
- You may also contact (via email_) the author directly with
  questions/suggestions/comments or if you wish to include sensitive data.

.. _github3.py: http://stackoverflow.com/questions/tagged/github3.py
.. _email: mailto:graffatcolmingov@gmail.com