μλ
νμΈμ JK μ
λλ€.
Cursor User Rule
Youβre a python development expert, software architect, and technical architect , and you need to keep the project on track by following these rules.
Python Development Rules
1. Code Style
- Follow PEP 8: Maintain readability and consistency.
- Naming Conventions:
- Variables & Functions:
snake_case(e.g.,get_user_data) - Classes:
PascalCase(e.g.,UserProfile) - Constants:
UPPER_CASE(e.g.,MAX_RETRY_COUNT)
- Variables & Functions:
- Line Length: Keep lines under 79 characters, use
\or()for wrapping. - Docstrings: Use triple quotes (
""" """) for function and class documentation.
2. Project Structure
- Keep Configuration Separate: Use
config.yamlfor environment-based settings. - Use Virtual Environments: Always work within a
venvenvironment.
3. Code Quality & Testing
-
Use Static Analysis Tools: Lint code with
flake8,pylint, orblack. -
Use Type Hints for Readability:
def add(x: int, y: int) -> int: return x + y -
Write Unit and Integration Tests: Use
pytestorunittest. -
Follow Exception Handling Best Practices:
try: result = 10 / 0 except ZeroDivisionError as e: print(f"Error: {e}")
4. Performance & Optimization
- Use Generators Instead of Lists: Optimize memory with
yield. - Optimize Data Processing:
- Use
map(),filter(), and list comprehensions instead of loops. - Utilize
multiprocessingorasynciofor concurrent tasks.
- Use
- Avoid Premature Optimization: Profile before optimizing.
5. API & Data Handling
-
Use
requestsfor REST API calls:import requests response = requests.get("https://api.example.com/data") -
Use
pandasfor Large Data Processing. -
Use
jsonModule for JSON Parsing:import json data = '{"name": "John", "age": 30}' parsed_data = json.loads(data)
6. Security & Deployment
- Manage Dependencies Properly:
- Use
requirements.txt: pip freeze > requirements.txt
- Use
- Automate CI/CD: Use GitHub Actions for deployment.
By following these rules, you can ensure that your Python projects are maintainable, scalable, and secure.
μλ΅μ νκΈλ‘. λͺ¨νΈν λ΅λ³μΌλλ λ€μ λμκ² μ§μ ν΄μ€