Skip to main content
In this article, we explore Cursor—a standalone application built as a fork of Visual Studio Code. Unlike extensions for Visual Studio Code or JetBrains products, Cursor offers an immersive environment where both chat and code reside within a single window. When you launch Cursor and press Ctrl+I, you’ll see options such as Add Files, Edit Refactor, and Add Code. The tool also allows you to switch between models like Cloud 3.5 Sonnet, GPT-4, 40 Mini, 01 Mini, 01 Preview, and Cursor Small. For illustration, we scaffold a typical Python application, with Cursor automatically generating the necessary files—much like what GitHub Copilot might do.
The image shows a code editor with a project structure on the left and a .gitignore file open in the main window. A pop-up window lists steps for setting up a Python project, including creating files like pyproject.toml and `requirements.txt'.
After accepting the generated files, you can inspect the project structure. The folder includes a source directory (src) with your project files, such as main.py.
The image shows a code editor with a project directory on the left and a .gitignore file open on the right, listing various files and directories to be ignored by Git.

The Generated Python Application

The generated main.py file contains a standard Python entry point, featuring a def main function along with an if __name__ == '__main__': check. It also sets up logging automatically:
A configuration file, config.py, is also generated. It uses a dataclass to manage configuration variables such as the API key and debug mode:
A simple test file is generated to serve as a placeholder for your test cases:
Additionally, the project includes a .gitignore file for ignoring file patterns (like virtual environments), a pyproject.toml with metadata and dependency details, and a basic requirements.txt listing both core and development dependencies. The pyproject.toml file looks like this:
The image shows a Visual Studio Code interface with a project directory open, displaying a requirements.txt file listing Python dependencies. The terminal at the bottom is ready for input.

Setting Up and Running the Application

To set up your Python environment, open the terminal and create a virtual environment:
Once the virtual environment is activated, install the dependencies:
You can then run your application:
If you encounter an error like “can’t open file ‘src/main.py’”, verify your directory structure. For instance, if your main file resides at src/my_project/main.py, run:
Upon execution, you should see log output indicating the application has started and finished, similar to:

Modifying the Application

Cursor supports interactive code generation. For example, you can modify your code so that it reads from a text file (demo.txt) and prints its contents line by line. An updated version of main.py might look like this:
Later, you might further modify the code to process the file by removing all spaces and writing the cleaned output to demo_no_spaces.txt:
After running the application, confirm that demo.txt has been processed and that demo_no_spaces.txt is created as expected.
The image shows a code editor with a file directory on the left and a text file open in the main area, displaying placeholder text. The terminal at the bottom shows log messages related to an application starting and finishing.

Refactoring into Functions and Writing Tests

For better code organization, it’s a good practice to refactor logic into separate functions. In this case, the file processing logic is moved into its own function:
Next, it’s important to write tests for your functions. In the file tests/test_main.py, you might add tests as follows:
If you encounter issues running tests, ensure your project is structured as a proper Python package (e.g., add empty __init__.py files) and adjust import statements accordingly. For example:
When running tests with pytest, common troubleshooting steps include verifying module import paths and installing your package in development mode with:

Final Thoughts

Cursor significantly speeds up code generation and prototyping. However, as demonstrated through iterative testing and debugging, a solid foundation in Python and best development practices remains essential. In our next article, we will explore building a larger application combining multiple AI-assisted development tools like ChatGPT, Tabnine, BlackboxAI, GitHub Copilot, and Cursor. Stay tuned for our next lesson as we delve deeper into advanced application development methodologies.

Watch Video