Main class: Github

class github.MainClass.Github(login_or_token: str | None = None, password: str | None = None, jwt: str | None = None, app_auth: AppAuthentication | None = None, base_url: str = 'https://api.github.com', timeout: int = 15, user_agent: str = 'PyGithub/Python', per_page: int = 30, verify: bool | str = True, retry: int | Retry | None = GithubRetry(total=10, connect=None, read=None, redirect=None, status=None), pool_size: int | None = None, seconds_between_requests: float | None = 0.25, seconds_between_writes: float | None = 1.0, auth: github.Auth.Auth | None = None)

This is the main class you instantiate to access the Github API v3.

Optional parameters allow different authentication methods.

Parameters
  • login_or_token – string deprecated, use auth=github.Auth.Login(…) or auth=github.Auth.Token(…) instead

  • password – string deprecated, use auth=github.Auth.Login(…) instead

  • jwt – string deprecated, use auth=github.Auth.AppAuth(…) or auth=github.Auth.AppAuthToken(…) instead

  • app_auth – github.AppAuthentication deprecated, use auth=github.Auth.AppInstallationAuth(…) instead

  • base_url – string

  • timeout – integer

  • user_agent – string

  • per_page – int

  • verify – boolean or string

  • retry – int or urllib3.util.retry.Retry object, defaults to github.Github.default_retry, set to None to disable retries

  • pool_size – int

  • seconds_between_requests – float

  • seconds_between_writes – float

  • auth – authentication method

close() → None

Close connections to the server. Alternatively, use the Github object as a context manager:

with github.Github(...) as gh:
  # do something
property requester

Return my Requester object.

For example, to make requests to API endpoints not yet supported by PyGitHub.

property rate_limiting

First value is requests remaining, second value is request limit.

property rate_limiting_resettime

Unix timestamp indicating when rate limiting will reset.

get_rate_limit() → github.RateLimit.RateLimit

Rate limit status for different resources (core/search/graphql).

Calls

`GET /rate_limit

<https://docs.github.com/en/rest/reference/rate-limit>`_

property oauth_scopes
Type

list of string

get_license(key: Opt[str] = NotSet) → License
Calls

GET /license/{license}

get_licenses() → PaginatedList[License]
Calls

GET /licenses

get_events() → PaginatedList[Event]
Calls

GET /events

get_user(login: Opt[str] = NotSet) → NamedUser | AuthenticatedUser
Calls

GET /users/{user} or GET /user

get_user_by_id(user_id: int) → NamedUser
Calls

GET /user/{id}

Parameters

user_id – int

Return type

github.NamedUser.NamedUser

get_users(since: Opt[int] = NotSet) → PaginatedList[NamedUser]
Calls

GET /users

get_organization(login: str) → Organization
Calls

GET /orgs/{org}

get_organizations(since: Opt[int] = NotSet) → PaginatedList[Organization]
Calls

GET /organizations

get_enterprise(enterprise: str) → github.Enterprise.Enterprise
Calls

GET /enterprises/{enterprise}

Parameters

enterprise – string

Return type

Enterprise

get_repo(full_name_or_id: int | str, lazy: bool = False) → Repository
Calls

GET /repos/{owner}/{repo} or GET /repositories/{id}

get_repos(since: Opt[int] = NotSet, visibility: Opt[str] = NotSet) → PaginatedList[Repository]
Calls

GET /repositories

Parameters
  • since – integer

  • visibility – string (‘all’,’public’)

get_project(id: int) → Project
Calls

GET /projects/{project_id}

get_project_column(id: int) → ProjectColumn
Calls

GET /projects/columns/{column_id}

get_gist(id: str) → Gist
Calls

GET /gists/{id}

get_gists(since: Opt[datetime] = NotSet) → PaginatedList[Gist]
Calls

GET /gists/public

get_global_advisory(ghsa_id: str) → GlobalAdvisory
Calls

GET /advisories/{ghsa_id}

Parameters

ghsa_id – string

Return type

github.GlobalAdvisory.GlobalAdvisory

get_global_advisories(type: Opt[str] = NotSet, ghsa_id: Opt[str] = NotSet, cve_id: Opt[str] = NotSet, ecosystem: Opt[str] = NotSet, severity: Opt[str] = NotSet, cwes: list[Opt[str]] | Opt[str] = NotSet, is_withdrawn: Opt[bool] = NotSet, affects: list[str] | Opt[str] = NotSet, published: Opt[str] = NotSet, updated: Opt[str] = NotSet, modified: Opt[str] = NotSet, keywords: Opt[str] = NotSet, before: Opt[str] = NotSet, after: Opt[str] = NotSet, per_page: Opt[str] = NotSet, sort: Opt[str] = NotSet, direction: Opt[str] = NotSet) → PaginatedList[GlobalAdvisory]
Calls

GET /advisories <https://docs.github.com/en/rest/security-advisories/global-advisories>

Parameters
  • type – Optional string

  • ghsa_id – Optional string

  • cve_id – Optional string

  • ecosystem – Optional string

  • severity – Optional string

  • cwes – Optional comma separated string or list of integer or string

  • is_withdrawn – Optional bool

  • affects – Optional comma separated string or list of string

  • published – Optional string

  • updated – Optional string

  • modified – Optional string

  • before – Optional string

  • after – Optional string

  • sort – Optional string

  • direction – Optional string

Return type

github.PaginatedList.PaginatedList of github.GlobalAdvisory.GlobalAdvisory

search_repositories(query: str, sort: Opt[str] = NotSet, order: Opt[str] = NotSet, **qualifiers: Any) → PaginatedList[Repository]
Calls

GET /search/repositories

Parameters
  • query – string

  • sort – string (‘stars’, ‘forks’, ‘updated’)

  • order – string (‘asc’, ‘desc’)

  • qualifiers – keyword dict query qualifiers

search_users(query: str, sort: Opt[str] = NotSet, order: Opt[str] = NotSet, **qualifiers: Any) → PaginatedList[NamedUser]
Calls

GET /search/users

Parameters
  • query – string

  • sort – string (‘followers’, ‘repositories’, ‘joined’)

  • order – string (‘asc’, ‘desc’)

  • qualifiers – keyword dict query qualifiers

Return type

PaginatedList of github.NamedUser.NamedUser

search_issues(query: str, sort: Opt[str] = NotSet, order: Opt[str] = NotSet, **qualifiers: Any) → PaginatedList[Issue]
Calls

GET /search/issues

Parameters
  • query – string

  • sort – string (‘comments’, ‘created’, ‘updated’)

  • order – string (‘asc’, ‘desc’)

  • qualifiers – keyword dict query qualifiers

Return type

PaginatedList of github.Issue.Issue

search_code(query: str, sort: Opt[str] = NotSet, order: Opt[str] = NotSet, highlight: bool = False, **qualifiers: Any) → PaginatedList[ContentFile]
Calls

GET /search/code

Parameters
  • query – string

  • sort – string (‘indexed’)

  • order – string (‘asc’, ‘desc’)

  • highlight – boolean (True, False)

  • qualifiers – keyword dict query qualifiers

Return type

PaginatedList of github.ContentFile.ContentFile

search_commits(query: str, sort: Opt[str] = NotSet, order: Opt[str] = NotSet, **qualifiers: Any) → PaginatedList[Commit]
Calls

GET /search/commits

Parameters
  • query – string

  • sort – string (‘author-date’, ‘committer-date’)

  • order – string (‘asc’, ‘desc’)

  • qualifiers – keyword dict query qualifiers

Return type

PaginatedList of github.Commit.Commit

search_topics(query: str, **qualifiers: Any) → PaginatedList[Topic]
Calls

GET /search/topics

Parameters
  • query – string

  • qualifiers – keyword dict query qualifiers

Return type

PaginatedList of github.Topic.Topic

render_markdown(text: str, context: Opt[Repository] = NotSet) → str
Calls

POST /markdown

Parameters
Return type

string

get_hook(name: str) → github.HookDescription.HookDescription
Calls

GET /hooks/{name}

get_hooks() → list[HookDescription]
Calls

GET /hooks

Return type

list of github.HookDescription.HookDescription

get_hook_delivery(hook_id: int, delivery_id: int) → github.HookDelivery.HookDelivery
Calls

GET /hooks/{hook_id}/deliveries/{delivery_id}

Parameters
  • hook_id – integer

  • delivery_id – integer

Return type

HookDelivery

get_hook_deliveries(hook_id: int) → list[HookDeliverySummary]
Calls

GET /hooks/{hook_id}/deliveries

Parameters

hook_id – integer

Return type

list of HookDeliverySummary

get_gitignore_templates() → list[str]
Calls

GET /gitignore/templates

get_gitignore_template(name: str) → GitignoreTemplate
Calls

GET /gitignore/templates/{name}

get_emojis() → dict[str, str]
Calls

GET /emojis

Return type

dictionary of type => url for emoji`

create_from_raw_data(klass: type[TGithubObject], raw_data: dict[str, Any], headers: dict[str, str | int] | None = None) → TGithubObject

Creates an object from raw_data previously obtained by GithubObject.raw_data, and optionally headers previously obtained by GithubObject.raw_headers.

Parameters
  • klass – the class of the object to create

  • raw_data – dict

  • headers – dict

Return type

instance of class klass

dump(obj: github.GithubObject.GithubObject, file: BinaryIO, protocol: int = 0) → None

Dumps (pickles) a PyGithub object to a file-like object. Some effort is made to not pickle sensitive information like the Github credentials used in the Github instance. But NO EFFORT is made to remove sensitive information from the object’s attributes.

Parameters

obj – the object to pickle :param file: the file-like object to pickle to :param protocol: the

pickling protocol
param obj

the object to pickle :param file: the file-like object to pickle to :param protocol: the

`pickling protocol <https://python.readthedocs.io/en/latest/library/pickle.html#data-
param obj

the object to pickle :param file: the file-like object to pickle to :param protocol: the

`pickling protocol <https://python.readthedocs.io/en/latest/library/pickle.html#data-

stream-format>`_ :param obj: the object to pickle :param file: the file-like object to pickle to :param

protocol: the `pickling protocol <https://python.readthedocs.io/en/latest/library/pickle.html#data- :param obj: the object to pickle :param file: the file-like object to pickle to :param protocol: the `pickling protocol <https://python.readthedocs.io/en/latest/library/pickle.html#data-

stream-format>`_

Parameters
load(f: BinaryIO) → Any

Loads (unpickles) a PyGithub object from a file-like object.

Parameters

f – the file-like object to unpickle from

Returns

the unpickled object

get_app(slug: Opt[str] = NotSet) → GithubApp
Calls

GET /apps/{slug} or GET /app