Skip to content

contents

Accessed as client.repos.contents; the async client mirrors it.

ReposContents

The repos.contents namespace.

change_files

change_files(
    owner: str,
    repo: str,
    *,
    author: Identity | None = None,
    branch: str | None = None,
    committer: Identity | None = None,
    dates: CommitDateOptions | None = None,
    files: list[ChangeFileOperation],
    force_overwrite_new_branch: bool | None = None,
    message: str | None = None,
    new_branch: str | None = None,
    signoff: bool | None = None,
) -> FilesResponse

Modify multiple files in a repository.

Parameters:

Name Type Description Default
owner str

owner of the repo

required
repo str

name of the repo

required
author Identity | None
None
branch str | None

branch (optional) to base this file from. if not given, the default branch is used

None
committer Identity | None
None
dates CommitDateOptions | None
None
files list[ChangeFileOperation]

list of file operations

required
force_overwrite_new_branch bool | None

(optional) will do a force-push if the new branch already exists

None
message str | None

message (optional) for the commit of this file. if not supplied, a default message will be used

None
new_branch str | None

new_branch (optional) will make a new branch from branch before creating the file

None
signoff bool | None

Add a Signed-off-by trailer by the committer at the end of the commit log message.

None

Returns:

Type Description
FilesResponse

FilesResponse.

Raises:

Type Description
ForbiddenError
  1. APIError is error format response.
NotFoundError
  1. APINotFound is a not found error response.
ConflictError
  1. APIConflict is a conflict empty response.
PayloadTooLargeError
  1. QuotaExceeded.
UnprocessableEntityError
  1. APIError is error format response.
LockedError
  1. APIRepoArchivedError is an error that is raised when an archived repo should be modified.

Operation ID: repoChangeFiles

create

create(
    owner: str,
    repo: str,
    filepath: str,
    *,
    author: Identity | None = None,
    branch: str | None = None,
    committer: Identity | None = None,
    content: str,
    dates: CommitDateOptions | None = None,
    force_overwrite_new_branch: bool | None = None,
    message: str | None = None,
    new_branch: str | None = None,
    signoff: bool | None = None,
) -> FileResponse

Create a file in a repository.

Parameters:

Name Type Description Default
owner str

owner of the repo

required
repo str

name of the repo

required
filepath str

path of the file to create

required
author Identity | None
None
branch str | None

branch (optional) to base this file from. if not given, the default branch is used

None
committer Identity | None
None
content str

content must be base64 encoded

required
dates CommitDateOptions | None
None
force_overwrite_new_branch bool | None

(optional) will do a force-push if the new branch already exists

None
message str | None

message (optional) for the commit of this file. if not supplied, a default message will be used

None
new_branch str | None

new_branch (optional) will make a new branch from branch before creating the file

None
signoff bool | None

Add a Signed-off-by trailer by the committer at the end of the commit log message.

None

Returns:

Type Description
FileResponse

FileResponse.

Raises:

Type Description
ForbiddenError
  1. APIError is error format response.
NotFoundError
  1. APINotFound is a not found error response.
ConflictError
  1. APIConflict is a conflict empty response.
PayloadTooLargeError
  1. QuotaExceeded.
UnprocessableEntityError
  1. APIError is error format response.
LockedError
  1. APIRepoArchivedError is an error that is raised when an archived repo should be modified.

Operation ID: repoCreateFile

delete

delete(
    owner: str,
    repo: str,
    filepath: str,
    *,
    author: Identity | None = None,
    branch: str | None = None,
    committer: Identity | None = None,
    dates: CommitDateOptions | None = None,
    force_overwrite_new_branch: bool | None = None,
    message: str | None = None,
    new_branch: str | None = None,
    sha: str,
    signoff: bool | None = None,
) -> FileDeleteResponse

Delete a file in a repository.

Parameters:

Name Type Description Default
owner str

owner of the repo

required
repo str

name of the repo

required
filepath str

path of the file to delete

required
author Identity | None
None
branch str | None

branch (optional) to base this file from. if not given, the default branch is used

None
committer Identity | None
None
dates CommitDateOptions | None
None
force_overwrite_new_branch bool | None

(optional) will do a force-push if the new branch already exists

None
message str | None

message (optional) for the commit of this file. if not supplied, a default message will be used

None
new_branch str | None

new_branch (optional) will make a new branch from branch before creating the file

None
sha str

sha is the SHA for the file that already exists

required
signoff bool | None

Add a Signed-off-by trailer by the committer at the end of the commit log message.

None

Returns:

Type Description
FileDeleteResponse

FileDeleteResponse.

Raises:

Type Description
BadRequestError
  1. APIError is error format response.
ForbiddenError
  1. APIError is error format response.
NotFoundError
  1. APIError is error format response.
PayloadTooLargeError
  1. QuotaExceeded.
LockedError
  1. APIRepoArchivedError is an error that is raised when an archived repo should be modified.

Operation ID: repoDeleteFile

get

get(owner: str, repo: str, filepath: str, *, ref: str | None = None) -> ContentsResponse

Gets the metadata and contents (if a file) of an entry in a repository, or a list of entries if a dir.

Parameters:

Name Type Description Default
owner str

owner of the repo

required
repo str

name of the repo

required
filepath str

path of the dir, file, symlink or submodule in the repo

required
ref str | None

The name of the commit/branch/tag. Default the repository's default branch (usually master)

None

Returns:

Type Description
ContentsResponse

ContentsResponse.

Raises:

Type Description
NotFoundError
  1. APINotFound is a not found error response.

Operation ID: repoGetContents

list

list(owner: str, repo: str, *, ref: str | None = None) -> list[ContentsResponse]

Gets the metadata of all the entries of the root dir.

Parameters:

Name Type Description Default
owner str

owner of the repo

required
repo str

name of the repo

required
ref str | None

The name of the commit/branch/tag. Default the repository's default branch (usually master)

None

Returns:

Type Description
list[ContentsResponse]

ContentsListResponse.

Raises:

Type Description
NotFoundError
  1. APINotFound is a not found error response.

Operation ID: repoGetContentsList

update

update(
    owner: str,
    repo: str,
    filepath: str,
    *,
    author: Identity | None = None,
    branch: str | None = None,
    committer: Identity | None = None,
    content: str,
    dates: CommitDateOptions | None = None,
    force_overwrite_new_branch: bool | None = None,
    from_path: str | None = None,
    message: str | None = None,
    new_branch: str | None = None,
    sha: str,
    signoff: bool | None = None,
) -> FileResponse

Update a file in a repository.

Parameters:

Name Type Description Default
owner str

owner of the repo

required
repo str

name of the repo

required
filepath str

path of the file to update

required
author Identity | None
None
branch str | None

branch (optional) to base this file from. if not given, the default branch is used

None
committer Identity | None
None
content str

content must be base64 encoded

required
dates CommitDateOptions | None
None
force_overwrite_new_branch bool | None

(optional) will do a force-push if the new branch already exists

None
from_path str | None

from_path (optional) is the path of the original file which will be moved/renamed to the path in the URL

None
message str | None

message (optional) for the commit of this file. if not supplied, a default message will be used

None
new_branch str | None

new_branch (optional) will make a new branch from branch before creating the file

None
sha str

sha is the SHA for the file that already exists

required
signoff bool | None

Add a Signed-off-by trailer by the committer at the end of the commit log message.

None

Returns:

Type Description
FileResponse

FileResponse.

Raises:

Type Description
ForbiddenError
  1. APIError is error format response.
NotFoundError
  1. APINotFound is a not found error response.
ConflictError
  1. APIConflict is a conflict empty response.
PayloadTooLargeError
  1. QuotaExceeded.
UnprocessableEntityError
  1. APIError is error format response.
LockedError
  1. APIRepoArchivedError is an error that is raised when an archived repo should be modified.

Operation ID: repoUpdateFile

AsyncReposContents

The repos.contents namespace.

change_files

change_files(
    owner: str,
    repo: str,
    *,
    author: Identity | None = None,
    branch: str | None = None,
    committer: Identity | None = None,
    dates: CommitDateOptions | None = None,
    files: list[ChangeFileOperation],
    force_overwrite_new_branch: bool | None = None,
    message: str | None = None,
    new_branch: str | None = None,
    signoff: bool | None = None,
) -> FilesResponse

Modify multiple files in a repository.

Parameters:

Name Type Description Default
owner str

owner of the repo

required
repo str

name of the repo

required
author Identity | None
None
branch str | None

branch (optional) to base this file from. if not given, the default branch is used

None
committer Identity | None
None
dates CommitDateOptions | None
None
files list[ChangeFileOperation]

list of file operations

required
force_overwrite_new_branch bool | None

(optional) will do a force-push if the new branch already exists

None
message str | None

message (optional) for the commit of this file. if not supplied, a default message will be used

None
new_branch str | None

new_branch (optional) will make a new branch from branch before creating the file

None
signoff bool | None

Add a Signed-off-by trailer by the committer at the end of the commit log message.

None

Returns:

Type Description
FilesResponse

FilesResponse.

Raises:

Type Description
ForbiddenError
  1. APIError is error format response.
NotFoundError
  1. APINotFound is a not found error response.
ConflictError
  1. APIConflict is a conflict empty response.
PayloadTooLargeError
  1. QuotaExceeded.
UnprocessableEntityError
  1. APIError is error format response.
LockedError
  1. APIRepoArchivedError is an error that is raised when an archived repo should be modified.

Operation ID: repoChangeFiles

create

create(
    owner: str,
    repo: str,
    filepath: str,
    *,
    author: Identity | None = None,
    branch: str | None = None,
    committer: Identity | None = None,
    content: str,
    dates: CommitDateOptions | None = None,
    force_overwrite_new_branch: bool | None = None,
    message: str | None = None,
    new_branch: str | None = None,
    signoff: bool | None = None,
) -> FileResponse

Create a file in a repository.

Parameters:

Name Type Description Default
owner str

owner of the repo

required
repo str

name of the repo

required
filepath str

path of the file to create

required
author Identity | None
None
branch str | None

branch (optional) to base this file from. if not given, the default branch is used

None
committer Identity | None
None
content str

content must be base64 encoded

required
dates CommitDateOptions | None
None
force_overwrite_new_branch bool | None

(optional) will do a force-push if the new branch already exists

None
message str | None

message (optional) for the commit of this file. if not supplied, a default message will be used

None
new_branch str | None

new_branch (optional) will make a new branch from branch before creating the file

None
signoff bool | None

Add a Signed-off-by trailer by the committer at the end of the commit log message.

None

Returns:

Type Description
FileResponse

FileResponse.

Raises:

Type Description
ForbiddenError
  1. APIError is error format response.
NotFoundError
  1. APINotFound is a not found error response.
ConflictError
  1. APIConflict is a conflict empty response.
PayloadTooLargeError
  1. QuotaExceeded.
UnprocessableEntityError
  1. APIError is error format response.
LockedError
  1. APIRepoArchivedError is an error that is raised when an archived repo should be modified.

Operation ID: repoCreateFile

delete

delete(
    owner: str,
    repo: str,
    filepath: str,
    *,
    author: Identity | None = None,
    branch: str | None = None,
    committer: Identity | None = None,
    dates: CommitDateOptions | None = None,
    force_overwrite_new_branch: bool | None = None,
    message: str | None = None,
    new_branch: str | None = None,
    sha: str,
    signoff: bool | None = None,
) -> FileDeleteResponse

Delete a file in a repository.

Parameters:

Name Type Description Default
owner str

owner of the repo

required
repo str

name of the repo

required
filepath str

path of the file to delete

required
author Identity | None
None
branch str | None

branch (optional) to base this file from. if not given, the default branch is used

None
committer Identity | None
None
dates CommitDateOptions | None
None
force_overwrite_new_branch bool | None

(optional) will do a force-push if the new branch already exists

None
message str | None

message (optional) for the commit of this file. if not supplied, a default message will be used

None
new_branch str | None

new_branch (optional) will make a new branch from branch before creating the file

None
sha str

sha is the SHA for the file that already exists

required
signoff bool | None

Add a Signed-off-by trailer by the committer at the end of the commit log message.

None

Returns:

Type Description
FileDeleteResponse

FileDeleteResponse.

Raises:

Type Description
BadRequestError
  1. APIError is error format response.
ForbiddenError
  1. APIError is error format response.
NotFoundError
  1. APIError is error format response.
PayloadTooLargeError
  1. QuotaExceeded.
LockedError
  1. APIRepoArchivedError is an error that is raised when an archived repo should be modified.

Operation ID: repoDeleteFile

get

get(owner: str, repo: str, filepath: str, *, ref: str | None = None) -> ContentsResponse

Gets the metadata and contents (if a file) of an entry in a repository, or a list of entries if a dir.

Parameters:

Name Type Description Default
owner str

owner of the repo

required
repo str

name of the repo

required
filepath str

path of the dir, file, symlink or submodule in the repo

required
ref str | None

The name of the commit/branch/tag. Default the repository's default branch (usually master)

None

Returns:

Type Description
ContentsResponse

ContentsResponse.

Raises:

Type Description
NotFoundError
  1. APINotFound is a not found error response.

Operation ID: repoGetContents

list

list(owner: str, repo: str, *, ref: str | None = None) -> list[ContentsResponse]

Gets the metadata of all the entries of the root dir.

Parameters:

Name Type Description Default
owner str

owner of the repo

required
repo str

name of the repo

required
ref str | None

The name of the commit/branch/tag. Default the repository's default branch (usually master)

None

Returns:

Type Description
list[ContentsResponse]

ContentsListResponse.

Raises:

Type Description
NotFoundError
  1. APINotFound is a not found error response.

Operation ID: repoGetContentsList

update

update(
    owner: str,
    repo: str,
    filepath: str,
    *,
    author: Identity | None = None,
    branch: str | None = None,
    committer: Identity | None = None,
    content: str,
    dates: CommitDateOptions | None = None,
    force_overwrite_new_branch: bool | None = None,
    from_path: str | None = None,
    message: str | None = None,
    new_branch: str | None = None,
    sha: str,
    signoff: bool | None = None,
) -> FileResponse

Update a file in a repository.

Parameters:

Name Type Description Default
owner str

owner of the repo

required
repo str

name of the repo

required
filepath str

path of the file to update

required
author Identity | None
None
branch str | None

branch (optional) to base this file from. if not given, the default branch is used

None
committer Identity | None
None
content str

content must be base64 encoded

required
dates CommitDateOptions | None
None
force_overwrite_new_branch bool | None

(optional) will do a force-push if the new branch already exists

None
from_path str | None

from_path (optional) is the path of the original file which will be moved/renamed to the path in the URL

None
message str | None

message (optional) for the commit of this file. if not supplied, a default message will be used

None
new_branch str | None

new_branch (optional) will make a new branch from branch before creating the file

None
sha str

sha is the SHA for the file that already exists

required
signoff bool | None

Add a Signed-off-by trailer by the committer at the end of the commit log message.

None

Returns:

Type Description
FileResponse

FileResponse.

Raises:

Type Description
ForbiddenError
  1. APIError is error format response.
NotFoundError
  1. APINotFound is a not found error response.
ConflictError
  1. APIConflict is a conflict empty response.
PayloadTooLargeError
  1. QuotaExceeded.
UnprocessableEntityError
  1. APIError is error format response.
LockedError
  1. APIRepoArchivedError is an error that is raised when an archived repo should be modified.

Operation ID: repoUpdateFile