This walkthrough explores using Agent Mode in Cursor AI to automate a Python project, including data processing, test generation, and documentation.
In this walkthrough, we’ll explore how to use Agent Mode in Cursor AI to automate a full Python project—from reading customer data to generating tests and documentation—in minutes. You’ll learn how to:
Enable and configure Autocompletion safely.
Define an allowlist/denylist for automated commands.
Generate code, tests, and docs with a single instruction set.
Run and verify the output locally using a Python virtual environment.
Ask the agent to scaffold these files:requirements.txt
Copy
Ask AI
pytest>=8.0
README.md
Copy
Ask AI
## Setup1. Clone the repository.2. Create a virtual environment: ```bash python -m venv venv ```text3. Activate: - macOS/Linux: `source venv/bin/activate` - Windows: `venv\Scripts\activate`4. Install dependencies: ```bash pip install -r requirements.txt ```text## Usage```bashpython process_customers.py```textReads `customers.csv`, writes names to `namevalues.csv` and phones to `phone.txt`.## Testing```bashpytest -v```text
Copy
Ask AI
import csvdef process_customer_data(input_file, name_output_file, phone_output_file): """ Process customer data from a CSV file and extract names and phone numbers. Args: input_file (str): Path to the input CSV file. name_output_file (str): Path to the output CSV file for names. phone_output_file (str): Path to the output TXT file for phone numbers. """ with open(input_file, newline='') as csvfile: reader = csv.DictReader(csvfile) names, phones = [], [] for row in reader: first = row.get('first_name', '').strip() last = row.get('last_name', '').strip() phone = row.get('phone_number', '').strip() if first or last: names.append((first, last)) if phone: phones.append(phone) with open(name_output_file, 'w', newline='') as namefile: writer = csv.writer(namefile) writer.writerow(['first_name', 'last_name']) writer.writerows(names) with open(phone_output_file, 'w') as phonefile: for phone in phones: phonefile.write(phone + '\n')if __name__ == '__main__': process_customer_data('customers.csv', 'namevalues.csv', 'phone.txt')