Back to Discover

#python

4 prompts found

Cursor Rules for Python: .mdc Rule Set From Your Repo Facts
📁 Agents

Cursor Rules for Python: .mdc Rule Set From Your Repo Facts

Ppromptstudio·Oct 15, 2026
No rating

Generate Cursor project rules for a Python repo: .mdc files with globs for source, tests, and migrations, built from your real tooling, layout, and commands.

Act as a Python tech lead who writes Cursor project rules for a team repo: short .mdc files in .cursor/rules/ that tell Cursor's Agent how this codebase is built, tested, and typed, using only facts from the repo. Inputs: - Python version, package manager, formatter, linter, and type checker as configured: [PythonToolchain] - Top-level folders and what lives in each: [RepoLayout] - Framework and the patterns the code follows (for example FastAPI routers, Django apps, plain scripts): [FrameworkPatterns] - Test runner, test folder, fixtures, and how external services are faked: [TestSetup] - Commands that exist in this repo, copied from the Makefile, pyproject scripts, or CI: [RealCommands] - Things the Agent must never do here: [NeverDo] - Mistakes the Agent has already made in this repo: [AgentMistakes] Generate: 1. A file plan: each .mdc file name, its rule type (Always Apply, Apply to Specific Files, Apply Intelligently, or Apply Manually), and why. 2. python-core.mdc: frontmatter with globs for source files and alwaysApply false, then rules for typing, imports, error handling, logging, and style that match PythonToolchain (point to the formatter instead of restating style). 3. tests.mdc: globs for the test folder only; how to write and name tests, use fixtures, and fake services per TestSetup. 4. One more file for the riskiest area in RepoLayout (for example migrations or the API layer), with a description so the Agent can pull it in when relevant. 5. A short always-apply file with the RealCommands and the NeverDo list. 6. A check list: every command, path, and tool named in the rules, each traced to an input, so nothing was invented. 7. Two test prompts to paste into Agent to confirm the rules load and change its behavior. Rules: - Name only tools, paths, and commands that appear in the inputs. - Keep each file under 60 lines; the whole set well under 500 lines. - Each line in AgentMistakes becomes one direct rule.

Django 4.2 LTS to 5.2 LTS Upgrade Planner: Python 3.10+ Floor, Stepwise 5.0 and 5.1 Hops, python -Wa Deprecation Sweep, django-upgrade Codemods, STORAGES Setting, index_together and pytz Removals, and a Third Party Package Matrix
💻 Coding

Django 4.2 LTS to 5.2 LTS Upgrade Planner: Python 3.10+ Floor, Stepwise 5.0 and 5.1 Hops, python -Wa Deprecation Sweep, django-upgrade Codemods, STORAGES Setting, index_together and pytz Removals, and a Third Party Package Matrix

Ppromptstudio·Oct 8, 2026
No rating

Plan a Django upgrade from 4.2 LTS to 5.2 LTS as a series of safe hops: environment floors, a deprecation sweep with warnings turned on, django-upgrade codemods, the removals that actually break 4.2 code, a package compatibility matrix, migration checks, and a deploy and rollback plan for each step.

Act as a senior Django engineer who has moved several production apps from one LTS release to the next, upgrades one minor version at a time, and lets the deprecation warnings drive the work list. Inputs: - Current versions: Django, Python, database engine and version, OS image: [CurrentStack] - requirements or pyproject dependency list with pinned versions: [Dependencies] - Settings excerpts and code patterns you know you use (storage settings, timezone handling, custom auth, model Meta options, test helpers): [SettingsAndPatterns] - Test suite size, CI setup, and how long a full run takes: [TestSuite] - Deploy method and tolerance for downtime: [DeployContext] - Output format: [Format] Generate: 1. Floors table: Django 5.x needs Python 3.10 or newer, and each release raises database minimums (for PostgreSQL, 5.2 expects 14 or newer). Compare against CurrentStack and list what must move first. 2. Hop plan: 4.2 to 5.0, then 5.1, then 5.2, each its own branch and deploy. Never jump straight to 5.2. 3. Warning sweep for each hop: run the suite with python -Wa manage.py test (or PYTHONWARNINGS=always with pytest), collect RemovedInDjango warnings, and fix all of them before bumping the version. 4. Codemods: run django-upgrade with --target-version for the hop, and pyupgrade for the Python floor, then review the diff by hand. 5. Breaking removals mapped to SettingsAndPatterns, for example: DEFAULT_FILE_STORAGE and STATICFILES_STORAGE replaced by STORAGES, index_together replaced by Meta.indexes with a migration, pytz support and USE_DEPRECATED_PYTZ removed in favor of zoneinfo, USE_L10N removed, logout over GET removed, assertQuerysetEqual renamed to assertQuerySetEqual, CheckConstraint check renamed to condition. For each: file, fix, test. 6. Package matrix from Dependencies: package, current pin, first version that supports the target Django, blocker yes or no, and an alternative if abandoned. 7. Migration safety: makemigrations --check after each hop, review any generated migration, and run migrations against a production sized copy. 8. Deploy and rollback for each hop from DeployContext, including what to watch in logs for the first day. 9. Mark anything you cannot confirm from the official release notes as "check the 5.x release notes". Constraints: - Ordered, checkable steps. Show commands exactly. No em dashes.

Pydantic v1 to v2 Migration Planner for FastAPI and Python Services: bump-pydantic First Pass, validator to field_validator, root_validator to model_validator, Config to ConfigDict, BaseSettings Move, and Behavior Changes
💻 Coding

Pydantic v1 to v2 Migration Planner for FastAPI and Python Services: bump-pydantic First Pass, validator to field_validator, root_validator to model_validator, Config to ConfigDict, BaseSettings Move, and Behavior Changes

Ppromptstudio·Oct 7, 2026
No rating

Migrate a codebase from Pydantic v1 to v2 without silent behavior changes: run bump-pydantic first, convert validators and root validators, move Config to model_config with renamed keys, replace dict, json, parse_obj, and from_orm calls, move BaseSettings to pydantic-settings, and catch Optional default and strict coercion changes with targeted tests.

Act as a Python backend engineer who has migrated several FastAPI and worker services from Pydantic v1 to v2, uses bump-pydantic for the mechanical pass, and knows which changes it cannot make for you: validator signatures, Optional defaults, and coercion that v1 did quietly. Inputs: - Current versions: Python, pydantic, FastAPI or other frameworks that depend on pydantic, and the target versions: [Versions] - Pasted model code: the models, validators, Config classes, and settings classes to migrate: [ModelCode] - Call sites: where the code uses .dict(), .json(), parse_obj, parse_raw, from_orm, schema(), copy(), or __fields__: [CallSites] - Test coverage and CI notes: what tests exist around these models and which payloads are known in production: [TestNotes] - Rollout constraints: big bang or gradual, other services that import these models, a deadline: [Rollout] - Output format: [Format] Generate: 1. A plan header: dependency changes from Versions (pydantic 2, pydantic-settings if BaseSettings is used, a FastAPI release that supports v2), and whether to use the pydantic.v1 namespace for a gradual path given Rollout. 2. bump-pydantic first pass: the command to run on the package and a list of what it will and will not rewrite in ModelCode. 3. Validator conversions: each @validator to @field_validator with @classmethod, each pre=True to mode='before', each always=True to validate_default, each values argument to info.data via ValidationInfo, and each @root_validator to @model_validator with the right mode. 4. Config conversions: class Config to model_config = ConfigDict(...) with renamed keys (orm_mode to from_attributes, allow_population_by_field_name to populate_by_name, anystr_strip_whitespace to str_strip_whitespace, schema_extra to json_schema_extra), and json_encoders replaced by field_serializer where needed. 5. Field changes: regex to pattern, const removed, __root__ models to RootModel, and Optional fields with no default that become required. 6. Call site replacements from CallSites: dict to model_dump, json to model_dump_json, parse_obj to model_validate, parse_raw to model_validate_json, from_orm to model_validate with from_attributes, schema to model_json_schema, copy to model_copy, __fields__ to model_fields. 7. Behavior change tests from TestNotes: payloads that v1 coerced (an int into a str field), Optional without default, validator order, and serialized output shape, each as a pytest case. 8. A rollout checklist: order of services, the diff to review, and what to watch in logs after deploy. Constraints: - Show before and after code for every model in ModelCode. Do not invent fields or call sites; mark anything unclear as CHECK. - Mark API names that changed between minor v2 releases as CHECK against the installed version. No em dashes.

💻 Coding

Advanced Python Data Analysis & Pandas Script Generator

PPromptDig·Mar 5, 2026
No rating

Quickly generate robust Python code for data cleaning, aggregation, and visualization using Pandas and Matplotlib/Seaborn.

Act as a Senior Data Scientist. Write a Python script using Pandas to analyze a dataset based on the following requirements: [Analysis Requirements]. The dataset has the following columns: [List of Columns]. Ensure the code follows these guidelines: Data Cleaning: Include robust error handling for missing values (NaN) and incorrect data types. Efficiency: Use vectorized Pandas operations instead of iterating through rows. Visualization: Provide code to generate at least two insightful visualizations using Matplotlib or Seaborn that directly address the analysis goals. Documentation: Include clear docstrings and inline comments explaining complex logic. Tone & Style: Professional, calm, and confident. Adhere to PEP-8 standards. Avoid unnecessary abstraction.