Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

89
Views
Serving directories with FastAPI application

I need to serve a directory that contains data, like how Apache serves an index, and I would like to serve it through my FastAPI application.

Is that possible with FastAPI or Starlette?

If not, Simplehttpserver alternatives suggests Twistd as a python package. Is it possible to have FastAPI redirect to a twistd server at the directory mount?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You're looking for the StaticFiles utility:

from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles

app = FastAPI()

app.mount("/", StaticFiles(directory="static"), name="static")

Arguments usage is documented on FastAPI documentation:

  • The first "/" refers to the path this "sub-application" will be "mounted" on. Kn this case, all paths will be handled by it.

  • The directory="static" refers to the name of the directory that contains your static files on your local filesystem.

  • The name="static" gives it a name that can be used internally by FastAPI.

All these parameters can be different than "static", adjust them with the needs and specific details of your own application.

Note: You will need to install aiofiles: pip install aiofiles

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!