Learn how to configure a GitHub Personal Access Token (PAT) with Poetry to access private GitHub repositories as dependencies during install. --- This video is based on the question https://stackoverflow.com/q/79283417/ asked by the user 'Sean' ( https://stackoverflow.com/u/7766024/ ) and on the answer https://stackoverflow.com/a/79283648/ provided by the user 'Sean' ( https://stackoverflow.com/u/7766024/ ) at 'Stack Overflow' website. Thanks to these great users and Stackexchange community for their contributions. Visit these links for original content and any more details, such as alternate solutions, latest updates/developments on topic, comments, revision history etc. For example, the original title of the Question was: How to use a GitHub PAT with Poetry? Also, Content (except music) licensed under CC BY-SA https://meta.stackexchange.com/help/licensing The original Question post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/by-sa/4.0/ ) license, and the original Answer post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/by-sa/4.0/ ) license. If anything seems off to you, please feel free to drop me a comment under this video. --- Accessing Private GitHub Repositories in Poetry with a Personal Access Token (PAT) When managing Python projects with Poetry, you might need to include private GitHub repositories as dependencies. However, poetry install often fails when trying to authenticate over HTTPS without proper credentials. The Problem Poetry uses Git under the hood to fetch dependencies. It does not trigger interactive username-password prompts for authentication. Setting a GITHUB_TOKEN environment variable or relying solely on Git Credential Manager often doesn't work seamlessly. This leads to failures when installing dependencies from private repositories. The Solution: Using Git Credential Store with a PAT Configure Git to store credentials globally: [[See Video to Reveal this Text or Code Snippet]] This instructs Git to save your credentials permanently after you enter them once. Trigger an authentication prompt manually: Perform a dummy clone or fetch operation from the private repository URL: [[See Video to Reveal this Text or Code Snippet]] When prompted, enter: Username: your GitHub username Password: your Personal Access Token (PAT) How this helps Poetry: Since Git now has your credentials stored locally, when Poetry invokes Git to fetch dependencies, it will use these saved credentials silently without needing new prompts. Additional Tips Generate a PAT with appropriate scopes: Make sure your token has at least repo scope for private repositories. Avoid hardcoding your token in URLs: Instead, rely on Git credential storage for security. Use poetry config for private repos: Poetry supports authenticating private repositories via poetry config http-basic if you prefer that method. Summary Because Poetry leverages Git but doesn't handle interactive authentication, setting up Git credential storage manually with your GitHub username and PAT enables seamless fetching of private repos during poetry install. This approach is simple, secure, and effective without modifying your project or compromising token security. Happy coding with Poetry and private GitHub dependencies!
The information provided is not trading advice. kdj.com does not assume any responsibility for any investments made based on the information provided in this article. Cryptocurrencies are highly volatile and it is highly recommended that you invest with caution after thorough research!
If you believe that the content used on this website infringes your copyright, please contact us immediately (info@kdj.com) and we will delete it promptly.