likkisai59/spond/fastapi-background-tasks

Claude Code and agent skill by likkisai59/spond

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

FastAPI BackgroundTasks for post-response operations like email notifications, audit logging, and fire-and-forget tasks

Install

npx vskill@latest install likkisai59/spond/fastapi-background-tasks

SKILL.md

The same SKILL.md was published earlier as likkisai59/spond/fastapi-background-tasks.

FastAPI Background Tasks Skill

Basic Usage

python
from fastapi import BackgroundTasks, FastAPI
app = FastAPI()
def send_email(recipient: str, message: str):
"""Background task - runs after response is sent."""
email_service.send(recipient, message)
@app.post("/notify/{email}")
async def send_notification(email: str, background_tasks: BackgroundTasks):
background_tasks.add_task(send_email, email, message="Hello!")
return {"message": "Notification queued"}

Key Concepts

Task Functions
  • Can be async def or regular def - FastAPI handles both
  • Run AFTER the response is returned to the client
  • Receive parameters passed via add_task()
Adding Tasks
python
background_tasks.add_task(
task_function, # The function to run
arg1, arg2, # Positional arguments
keyword_arg=value # Keyword arguments
)

Best Practices

1. Keep Tasks Simple
python
# Good - single responsibility
def send_email(recipient: str, template: str, data: dict):
email_service.send(recipient, template, data)
2. Handle Errors Gracefully
python
async def safe_send_email(recipient: str, order_id: str):
try:
await email_service.send(recipient, order_id)
except Exception as e:
logger.error(f"Failed to send email: {e}", extra={"order_id": order_id})
3. Do Not Block in Tasks
python
# BAD - synchronous HTTP call blocks the event loop
def send_webhook(url: str, data: dict):
requests.post(url, json=data) # Blocks!
# GOOD - use async HTTP client
async def send_webhook(url: str, data: dict):
async with httpx.AsyncClient() as client:
await client.post(url, json=data)
4. Pass Data, Not Objects
python
# BAD - passing complex objects that may have state issues
background_tasks.add_task(process_order, order_object)
# GOOD - pass identifiers and fetch fresh data
background_tasks.add_task(process_order, order_id=str(order.id))

Comparison with Alternatives

FeatureBackgroundTasksCeleryAPScheduler
Setup complexityNoneHighMedium
External dependenciesNoneRedis/RabbitMQDatabase
DistributedNoYesNo
Scheduled jobsNoYesYes
Task persistenceNoYesVaries
Best forSimple post-request tasksHeavy workloadsScheduled jobs

BackgroundTasks vs asyncio.create_task()

python
# asyncio.create_task - runs IMMEDIATELY (may delay response)
asyncio.create_task(send_email(order))
# BackgroundTasks.add_task - runs AFTER response is sent
background_tasks.add_task(send_email, order_id=str(order.id))

Technical Details

  • BackgroundTasks comes from starlette.background
  • Tasks run in the same process (share memory/variables)
  • If the server crashes, pending tasks are lost
  • For critical tasks, use a message queue (Celery) instead

References

Security

  • Security scanPassed, 90 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
0

Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/likkisai59/spond/fastapi-background-tasks/badge)](https://verified-skill.com/skills/likkisai59/spond/fastapi-background-tasks)

Something wrong with this skill or its page? Tell us.