Hacker News new | past | comments | ask | show | jobs | submit login
Ask HN: Where to Host a FastAPI App
18 points by techlover14159 6 months ago | hide | past | favorite | 33 comments
I am looking for something similar to pythonanywhere which is great for WSGI apps but it doesn't support ASGI apps which I need.



PythonAnywhere founder here: your timing is impeccable! Literally today we started our beta-testing of our initial implementation of ASGI support. Features are limited right now but you can start and run a FastAPI site with a single request to the API -- no UI yet, but we decided to release the backend while we were working on the frontend so that people could give the tires a kick ASAP. If you're interested, drop us a line at the usual support address and I'm sure we can on-board you if it does what you need.


That was fast.

Are CEOs just smashing refresh on HN looking for their names? (jk, I know it's some API driven thing)


Coincidences can happen. :)


LOL! I was just scrolling through HN before bed and spotted a headline about FastAPI, which was very much top of my mind after the go-live on the beta today. Clicked through and saw it mentioned us, so posted right away.


Probably an unpopular opinion with everyone preferring to hand over money for convenience, but the advantage of learning to be able to do this yourself with nginx will bring a lifetime of self reliance/money saving.

Yes it will take time to learn it, but the ability to spin up a super cheap digital-ocean/linode/hetzner node is a valuable skill to have in your back pocket.


Great choice. Setting up https from scratch using nginx is something you should definitely do ONCE in your life but then use automated tools such as nginx-proxy/acme-companion.


Or you could use caddy from the get go


The Apache stuff I learned like 20 years ago still works - especially for not-huge sites (<600RPS). Point being, once you get this sys-admin task done it's super repeatable (regardless of server). And from one, moving between isn't that hard either. Dozens of personal services can run on a $5/mo VPS. One I have now is nginx to SSL terminate to 8 backend docker-things


Still running apache for my side projects too, it's very convenient and easy to deal.


Good pun +1 for that.

I recommend nginx or Apache for the learning exercise. Then go with whatever best suits your use case. My rule is choose that which fits the objective and which doesn't overburden with cognitive load. So I don't use Apache for anything and sometimes just use python's built in. suitability for purpose and usability is what counts for me.


idk it costs me like 6 dollars to run a docker container on aws's container service with .5 core. one server by hand isn't to bad, once you want to scale horizontally its going to be tedious, the tools start getting annoyingly complex. locking down everything is a headache, and theres always a nagging feeling that you didn't do it right and one well timed script from getting taken over. you also need to deal with code deploys. just dumping the python code in a docker container and uploading it is easy. updating a hand set up server, again is tedious and error prone.


Sure it's not for everyone. I learnt a lot doing cash strapped startups where there wasn't a devops person. AWS can get expensive, especially when you start using more and more services (lambda,dynamodb,rds,elasticache etc) although it can be easily scaled.

Note, you probably shouldn't do it by hand (setting up your own servers). You'd use Ansible/Terraform.

For those that are interested but not quite ready, here's a great article [0].

[0] https://github.com/fpereiro/backendlore.


Some options:

- https://fly.io/

- https://render.com/

Your best bet is probably to containerize your application instead of looking for services that natively support ASGI.


Fly.io! Your instance auto-sleeps and saves you money compared to other static VPS. Also no vendor lock-in as it's based on Docker containers.


I think it depends on your goals. If this is a serious project and your first deployment, consider Platform-as-a-Service (PaaS) and a managed database (DBaaS). If it's a hobby project and you're interested in learning about infrastructure you could run your app, database, and reverse proxy on a single Linux VM, which any cloud will offer.

For PaaS, if you want a set-it and forget-it solution check out Render or DigitalOcean App Platform. If you want to dive a little bit deeper and learn about different offerings from the major cloud providers, compare the features of Google Cloud Run and App Engine, or AWS App Runner. All of these providers offer databases too.

Either way I recommend learning how to containerize your app because then you can run anything almost anywhere.


>If this is a serious project and your first deployment, consider Platform-as-a-Service (PaaS) and a managed database (DBaaS). If it's a hobby project and you're interested in learning about infrastructure you could run your app, database, and reverse proxy on a single Linux VM, which any cloud will offer.

So, I'm currently dealing with this (like, today.) I containerized my web app. I started out with a $4 Droplet on DO. SSH'd into it, installed all the Docker stuff and cloned my repo. Could not even run npm ci with the resources available.

I kept having to resize the VM. First up to the $6 then I was running into different stuff. I ended up going up to the $24 / mo option just to get the image building. I didn't step up to every price point, because I just wanted to get the thing working, but I was really surprised at this. I don't think my Docker container is particularly resource intensive. I dialed it back to the $12 / mo option and will see how it goes.

But at least I have my whole app in a Dockerfile and the remaining infrastructure in a Docker Compose file. I like having that level of control.

Personally, my issue with PaaS is on top of being more expensive and potential vendor lock in, it often has its own little gotchas that end up not making it more convenient than the "hard way." I tried to use Digital Ocean's App Platform to build my image instead before and it was giving me Vite issues. It literally wouldn't compile even though it was compiling just fine locally and on the VM.

I think about other services like Cloudinary too. Compared to just using Sharp to do things like image transcoding. I just don't see the value there.

Overall, devops is not my area. I used to consider myself a front-end developer. But I'm glad I have been learning these skills. I don't think these "value added" services are worth the squeeze.


> Could not even run npm ci with the resources available. I kept having to resize the VM. First up to the $6 then I was running into different stuff. I ended up going up to the $24 / mo option just to get the image building.

This makes very little sense to me. I’ve been using $4 droplets to host a variety of projects (much of the time on the same server) and have rarely hit such issues.

How inefficient is the code for it to need the $24 droplet?

You probably shouldn’t be building the image on the droplet though, maybe build locally, release to docker registry, and only pull the image from the server.


That's what I'm going to move to. It's part of the learning process for me. I want to set the image to build when I push to my repository.

I also think moving from npm to pnpm and leveraging caching will help. But the dockerfile itself is very very simple.


You can fork Replit's FastAPI template and edit it and deploy from the online editor https://replit.com/@replit/FastAPI?v=1

It uses uvicorn as recommended by the FastAPI docs.


I switched[1] to Hypercorn[2] because Uvicorn currently supports HTTP/1.1[3] and WebSockets

[1] https://github.com/hbcondo/revenut-api/blob/main/Procfile

[2] https://github.com/pgjones/hypercorn

[3] https://www.uvicorn.org


I have hosted FastAPI apps in the past using Vercel Serverless Functions [0]. The Python runtime is available in Beta on all plans.

[0]: https://vercel.com/docs/functions/serverless-functions/runti...



Literally any $5/mo VPS provider?




If you want to try new options I highly recommend:

* encore.dev

* koyeb.com

They are not as popular as other services but they provide a good service very cheap/free.

I have no complains so far for my 4 pet projects (I use litestar with docker for all my projects)


Thanks for the shoutout, happy to answer any questions about Encore if anyone's curious. (I'm the founder.)


I am very happy with gcp. You can setup a cloud build trigger to build and push to gcr then deploy to gke or cloud run. A bit more involved that pythonanywhere but more flexible and arguably more powerful.


I wrote a couple of toy FastAPI apps (not production) and I'm happy with Fly.io. Apparently they have lots of downtime issues, but I've never run into them (yet)


https://deta.space is underrated.


Google App Engine. Most apps will live comfortably in the free / extremely cheap tier.


Google Cloud Run - tl;dr push a container that listens on PORT. Google Cloud runs it.

The quick start is even easier to get going since they have some hooks to quickly build the container: https://cloud.google.com/run/docs/quickstarts/build-and-depl...


cheapest vps you can find plus dokku




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: