Utilities¶
Authentication¶
-
class
github.Auth.
Login
(login: str, password: str)¶ This class is used to authenticate with login and password.
-
property
username
¶ The username.
-
property
password
¶ The password.
-
property
-
class
github.Auth.
Token
(token: str)¶ This class is used to authenticate with a single constant token.
-
property
token_type
¶ The type of the auth token as used in the HTTP Authorization header, e.g. Bearer or Basic.
- Returns
token type
-
property
token
¶ The auth token as used in the HTTP Authorization header.
- Returns
token
-
property
-
class
github.Auth.
JWT
¶ This class is the base class to authenticate with a JSON Web Token (JWT).
-
property
token_type
¶ The type of the auth token as used in the HTTP Authorization header, e.g. Bearer or Basic.
- Returns
token type
-
property
-
class
github.Auth.
AppAuth
(app_id: Union[int, str], private_key: str, jwt_expiry: int = 300, jwt_issued_at: int = -60, jwt_algorithm: str = 'RS256')¶ This class is used to authenticate as a GitHub App.
-
property
token
¶ The auth token as used in the HTTP Authorization header.
- Returns
token
-
get_installation_auth
(installation_id: int, token_permissions: Optional[Dict[str, str]] = None, requester: Optional[github.Requester.Requester] = None) → github.Auth.AppInstallationAuth¶ Creates a github.Auth.AppInstallationAuth instance for an installation.
- Parameters
installation_id – installation id
token_permissions – optional permissions
requester – optional requester with app authentication
- Returns
-
create_jwt
(expiration: Optional[int] = None) → str¶ Create a signed JWT https://docs.github.com/en/developers/apps/building-github-apps/authenticating-with-github-apps#authenticating-as-a-github-app
- Return string
jwt
-
property
-
class
github.Auth.
AppAuthToken
(token: str)¶ This class is used to authenticate as a GitHub App with a single constant JWT.
-
property
token
¶ The auth token as used in the HTTP Authorization header.
- Returns
token
-
property
-
class
github.Auth.
AppInstallationAuth
(app_auth: github.Auth.AppAuth, installation_id: int, token_permissions: Optional[Dict[str, str]] = None, requester: Optional[github.Requester.Requester] = None)¶ This class is used to authenticate as a GitHub App Installation.
-
property
token_type
¶ The type of the auth token as used in the HTTP Authorization header, e.g. Bearer or Basic.
- Returns
token type
-
property
token
¶ The auth token as used in the HTTP Authorization header.
- Returns
token
-
property
-
class
github.Auth.
AppUserAuth
(client_id: str, client_secret: str, token: str, token_type: Optional[str] = None, expires_at: Optional[datetime.datetime] = None, refresh_token: Optional[str] = None, refresh_expires_at: Optional[datetime.datetime] = None, requester: Optional[github.Requester.Requester] = None)¶ This class is used to authenticate as a GitHub App on behalf of a user.
-
class
ApplicationOAuth
(requester: Requester, headers: dict[str, Any], attributes: Any, completed: bool)¶ This class is used for identifying and authorizing users for Github Apps.
The reference can be found at https://docs.github.com/en/developers/apps/building-github-apps/identifying-and-authorizing-users-for-github-apps
-
get_access_token
(code: str, state: str | None = None) → AccessToken¶
-
get_login_url
(redirect_uri: str | None = None, state: str | None = None, login: str | None = None) → str¶ Return the URL you need to redirect a user to in order to authorize your App.
-
refresh_access_token
(refresh_token: str) → AccessToken¶ - Calls
- Parameters
refresh_token – string
-
-
property
token_type
¶ The type of the auth token as used in the HTTP Authorization header, e.g. Bearer or Basic.
- Returns
token type
-
property
token
¶ The auth token as used in the HTTP Authorization header.
- Returns
token
-
class
Logging¶
-
github.
enable_console_debug_logging
() → None¶ This function sets up a very simple logging configuration (log everything on standard output) that is useful for troubleshooting.
Error Handling¶
-
exception
github.GithubException.
GithubException
(status: int, data: Any = None, headers: Optional[Dict[str, str]] = None, message: Optional[str] = None)¶ Error handling in PyGithub is done with exceptions. This class is the base of all exceptions raised by PyGithub (but
github.GithubException.BadAttributeException
).Some other types of exceptions might be raised by underlying libraries, for example for network-related issues.
-
property
status
¶ The status returned by the Github API.
-
property
data
¶ The (decoded) data returned by the Github API.
-
property
headers
¶ The headers returned by the Github API.
-
property
-
exception
github.GithubException.
BadCredentialsException
(status: int, data: Any = None, headers: Optional[Dict[str, str]] = None, message: Optional[str] = None)¶ Exception raised in case of bad credentials (when Github API replies with a 401 or 403 HTML status)
-
exception
github.GithubException.
UnknownObjectException
(status: int, data: Any = None, headers: Optional[Dict[str, str]] = None, message: Optional[str] = None)¶ Exception raised when a non-existing object is requested (when Github API replies with a 404 HTML status)
-
exception
github.GithubException.
BadUserAgentException
(status: int, data: Any = None, headers: Optional[Dict[str, str]] = None, message: Optional[str] = None)¶ Exception raised when request is sent with a bad user agent header (when Github API replies with a 403 bad user agent HTML status)
-
exception
github.GithubException.
RateLimitExceededException
(status: int, data: Any = None, headers: Optional[Dict[str, str]] = None, message: Optional[str] = None)¶ Exception raised when the rate limit is exceeded (when Github API replies with a 403 rate limit exceeded HTML status)
-
exception
github.GithubException.
BadAttributeException
(actualValue: Any, expectedType: Union[Dict[Tuple[Type[str], Type[str]], Type[dict]], Tuple[Type[str], Type[str]], List[Type[dict]], List[Tuple[Type[str], Type[str]]]], transformationException: Optional[Exception])¶ Exception raised when Github returns an attribute with the wrong type.
-
property
actual_value
¶ The value returned by Github.
-
property
expected_type
¶ The type PyGithub expected.
-
property
transformation_exception
¶ The exception raised when PyGithub tried to parse the value.
-
property
-
exception
github.GithubException.
TwoFactorException
(status: int, data: Any = None, headers: Optional[Dict[str, str]] = None, message: Optional[str] = None)¶ Exception raised when Github requires a onetime password for two-factor authentication.
-
exception
github.GithubException.
IncompletableObject
(status: int, data: Any = None, headers: Optional[Dict[str, str]] = None, message: Optional[str] = None)¶ Exception raised when we can not request an object from Github because the data returned did not include a URL.
Default argument¶
github.NotSet
is a special value for arguments you don’t want to provide. You should not have to manipulate it directly, because it’s the default value of all parameters accepting it. Just note that it is different from None
, which is an allowed value for some parameters.
Pagination¶
-
class
github.PaginatedList.
PaginatedList
¶ This class abstracts the pagination of the API.
You can simply enumerate through instances of this class:
for repo in user.get_repos(): print(repo.name)
If you want to know the total number of items in the list:
print(user.get_repos().totalCount)
You can also index them or take slices:
second_repo = user.get_repos()[1] first_repos = user.get_repos()[:10]
If you want to iterate in reversed order, just do:
for repo in user.get_repos().reversed: print(repo.name)
And if you really need it, you can explicitly access a specific page:
some_repos = user.get_repos().get_page(0) some_other_repos = user.get_repos().get_page(3)
Input classes¶
-
class
github.InputFileContent.
InputFileContent
(content: str, new_name: Union[str, github.GithubObject._NotSetType] = NotSet)¶ This class represents InputFileContents.
-
class
github.InputGitAuthor.
InputGitAuthor
(name: str, email: str, date: Union[str, github.GithubObject._NotSetType] = NotSet)¶ This class represents InputGitAuthors.
-
class
github.InputGitTreeElement.
InputGitTreeElement
(path: str, mode: str, type: str, content: Opt[str] = NotSet, sha: Opt[str | None] = NotSet)¶ This class represents InputGitTreeElements.