How to Use GitHub Copilot with Python
GitHub Copilot is a tool that helps developers write code faster and more efficiently by providing suggestions and even entire blocks of code based on comments, variable names, function names, and more.
GitHub Copilot saves time when writing standard code structures and algorithms. It is helpful for beginners just learning to develop in a new language and for experienced developers who want to avoid manually writing repetitive functions and structures.
GitHub Copilot can be integrated into various development environments, including:
Visual Studio
Neovim
VS Code
JetBrains IDEs
It also supports a wide range of programming languages, such as:
Python
JavaScript
Go
Java
C#
TypeScript
C++
Ruby
Rust
Shell script
Kotlin
Swift
GitHub Copilot is compatible with popular frameworks and libraries like React, AngularJS, VueJS, Spring, Django, Ruby on Rails, and more.
In this tutorial, we’ll explain how to use GitHub Copilot when developing in Python and how it can help improve coding efficiency.
Key Features of GitHub Copilot
Autocomplete – Provides real-time code suggestions and autocompletion.
Code Prediction – Predicts the next steps in your code and offers options to complete structures.
Code Search – Helps find relevant code within a project using keywords or code snippets.
Code Refactoring – Assists in optimizing and modifying existing code with refactoring features.
GitHub Copilot is currently available as a subscription service for $10 monthly.
How GitHub Copilot Works
GitHub Copilot provides suggestions and autocomplete features based on user comments written in natural language and existing code. To achieve this, GitHub trained Copilot using publicly available repositories hosted on its platform.
The effectiveness of Copilot depends on the availability of public repositories in a given programming language. It works well with popular languages like Python and offers reliable suggestions. However, for less common languages, its performance may be weaker, providing fewer and less accurate recommendations.
Integrating GitHub Copilot with PyCharm
PyCharm, a JetBrains IDE, supports GitHub Copilot. To integrate it into your project, follow these steps:
Visit github.com/features/copilot and click Get started for free.
Log in to GitHub or create an account.
Now, you can install the GitHub Copilot plugin in PyCharm:
Open PyCharm.
Go to File > Settings.
Navigate to Plugins and search for GitHub Copilot.
Click Install to add the plugin.
After installation, open the Tools menu, find GitHub Copilot and click Login to GitHub.
A window will appear with an authorization link and a special code. Follow the link, enter the code, and confirm authorization.
Now, GitHub Copilot is fully integrated into your PyCharm project.
How to Use GitHub Copilot
Let's write a simple function to verify that we have successfully installed the GitHub Copilot plugin.
For example, start typing a function to add two numbers, like:
def add(a, b):
As you begin typing, Copilot will suggest completing the function:
Suggested code appears in gray and italicized text.
To accept a suggestion, press Tab.
To reject a suggestion, press Esc.
Useful GitHub Copilot Shortcuts
Action
Windows
Mac
Activate inline suggestions
Alt+\
Option+\
View next suggestion
Alt+]
Option+]
View previous suggestion
Alt+[
Option+[
Accept suggestion
Tab
Tab
Reject suggestion
Esc
Esc
Open all suggestions in a new window
Ctrl+Enter
Ctrl+Enter
Using Copilot with Comments
GitHub Copilot doesn’t just rely on function names—it also generates code based on comments.
For example, if you write a function for matrix multiplication with a descriptive comment:
def multiply_matrices(A, B):
# Multiply matrix A and B and return the result
Copilot may suggest the following:
def multiply_matrices(A, B):
# Multiply matrix A and B and return the result
rows1 = len(A)
cols1 = len(A[0])
rows2 = len(B)
cols2 = len(B[0])
if cols1 != rows2:
raise ValueError("The number of columns in the first matrix must be equal to the number of rows in the second matrix")
result = [[0 for j in range(cols2)] for i in range(rows1)]
for i in range(rows1):
for j in range(cols2):
for k in range(cols1):
result[i][j] += A[i][k] * B[k][j]
return result
To verify that this function works correctly, let’s use the NumPy library:
import numpy as np
matrix1 = [[15,24],[12,44]]
matrix2 = [[112, 22],[55,90]]
m1 = np.array([[15,24],[12,44]])
m2 = np.array([[112, 22],[55,90]])
print(multiply_matrices(matrix1, matrix2),'\n')
print(np.dot(m1, m2))
Output:
[[3000, 2490], [3764, 4224]]
[[3000 2490]
[3764 4224]]
As you can see, the function Copilot correctly performs matrix multiplication.
Cons of Using GitHub Copilot
GitHub Copilot is a very useful tool, but it has some drawbacks.
Copilot Doesn't Test Its Code
The code suggested by Copilot may contain errors. It does not perform self-checks, meaning developers must test the generated code themselves. Additionally, Copilot doesn’t always produce optimized code, both in terms of efficiency and structure. In summary, all Copilot-generated code must be reviewed and tested.
Conflicts with IDEs
Modern Integrated Development Environments (IDEs) do more than just provide a space for writing and debugging code—they also offer built-in suggestions. For example, when using a built-in function in PyCharm, the IDE provides information about its attributes. At the same time, Copilot might suggest something different, which can be confusing for the developer.
Potential Copyright Issues
This is a controversial aspect of using Copilot in commercial development. Since Copilot was trained on public repositories, it could theoretically suggest licensed code. This raises concerns about intellectual property rights when using Copilot-generated code in proprietary projects.
Negative Impact on Developer Skills
Copilot doesn’t teach developers how to write code—it writes it for them. For junior developers, it’s important to gain hands-on experience by implementing common functions and algorithms manually. Over-reliance on Copilot might slow down skill development.
Conclusion
GitHub Copilot is a useful tool for handling repetitive coding tasks. According to GitHub’s own research:
74% of developers reported focusing on more enjoyable aspects of their work,
88% felt more productive,
96% completed repetitive tasks faster.
Copilot should be seen as an assistant—someone you can delegate tasks to while focusing on more important and complex problems. However, developers must carefully review all code generated by Copilot to ensure quality and correctness.
24 March 2025 · 6 min to read