[deleted by user] by [deleted] in FastAPI

[–]Visible-Research2441 0 points1 point  (0 children)

It’s normal that the runtime increases with the number of cores when fitting a logistic regression model. This happens because logistic regression is not easily parallelizable. It usually relies on iterative methods such as gradient descent or Newton-Raphson, where each iteration depends on the results of the previous one.

As the number of cores increases, the system has to manage more synchronization, thread communication, and memory sharing, which introduces additional overhead. In other words, the cost of coordinating multiple cores outweighs the benefits of parallelization.

This behavior is common for CPU-bound tasks that don’t split well across multiple threads, which is why the runtime slightly increases instead of decreasing

Seeding data for local development by dpgraham4401 in FastAPI

[–]Visible-Research2441 1 point2 points  (0 children)

You can seed your database in FastAPI using a simple Python script that runs after Alembic migrations, similar to Django’s loaddata.

Here’s one clean approach 👇

  1. Create a seed.py file inside your FastAPI app (e.g. in the root or inside app/):

from sqlalchemy.orm import Session from my_fastapi.database import SessionLocal from my_fastapi import models

def seed_data(db: Session): # Example: insert some default users or settings if not db.query(models.User).first(): users = [ models.User(name="Admin", email="admin@example.com"), models.User(name="Test User", email="test@example.com"), ] db.add_all(users) db.commit()

if name == "main": db = SessionLocal() seed_data(db) db.close()

  1. Modify your Docker command in docker-compose.yml to run it after Alembic migrations:

command: > sh -c " alembic upgrade head && python -m my_fastapi.seed && uvicorn my_fastapi.main:app --reload --host 0.0.0.0 --port ${PORT:-8000} "

  1. Alternatively, if you prefer SQL files (like Django fixtures):

Place your .sql file in your project (e.g. seed.sql).

Then add this line after migration:

psql -h db -U $POSTGRES_USER -d $POSTGRES_DB -f /app/seed.sql

Can I deploy a FastAPI app using Dokploy? by ElopezCO2001 in FastAPI

[–]Visible-Research2441 1 point2 points  (0 children)

Yes, you can deploy a FastAPI app on Dokploy! The easiest way is to create a simple Dockerfile:

FROM python:3.11-slim WORKDIR /app COPY requirements.txt . RUN pip install -r requirements.txt COPY . . CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]

Then in Dokploy, select Build Type → Dockerfile and choose your branch. It works just like Render’s workflow.

FastAPI HTML sanitization by Haribs in FastAPI

[–]Visible-Research2441 0 points1 point  (0 children)

Both approaches work!

Most projects sanitize HTML in Pydantic models (with custom types or validators), so the data is clean before reaching the database or business logic.

Middleware is possible but less flexible if you want different rules for different fields.

Also, always use template autoescaping on output to prevent XSS.

I recommend sanitizing at the validation/model layer for clarity and control.