Generate github personal access token (PAT) by command line or SDK

1.7k views Asked by At

I am looking for the command or SDK, such as python, to generate new personal access token (PAT) in Github, but I didn't see any API for it.

https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token

All the documents are about to login github from website, and manually generate it.

Are there any automation way?

1

There are 1 answers

0
ExplosiveFridge On

Unfortunately, this isn't something that can be done completely programmatically. Creating PATs requires sudo mode on GitHub, which prompts the user to authenticate.

The best you can do is use a command to prefill parts of the creation of a PAT (scopes, description, etc.). This isn't currently a feature of any Python package, though something similar exists in this R package: https://usethis.r-lib.org/reference/github-token.html