# Flask and CrewAI

**URL:** <https://community.crewai.com/t/flask-and-crewai/1122>\
**Category:** CrewAI Community Support\
**Created:** [October 29, 2024, 5:25pm UTC](https://community.crewai.com/t/flask-and-crewai/1122 "2024-10-29T17:25:17Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![marcNY](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/marcny/32/825_2.png) [@marcNY](https://community.crewai.com/u/marcNY)\
**Post date:** [October 29, 2024, 5:25pm UTC](https://community.crewai.com/t/flask-and-crewai/1122/1 "2024-10-29T17:25:17Z")

</div>

I am trying to put my CrewAI behind a Flask server to connect it to a NextJS WebAPP.  
However because getting the result from CrewAI takes 30s the NextJS disconnect before getting the results.  
How do you set up Flask to handle the long timeline for the results?

---

<div class="post-metadata">

**Author:** ![Dabnis](https://avatars.discourse-cdn.com/v4/letter/d/858c86/32.png) [@Dabnis](https://community.crewai.com/u/Dabnis)\
**Post date:** [October 29, 2024, 5:32pm UTC](https://community.crewai.com/t/flask-and-crewai/1122/2 "2024-10-29T17:32:31Z")

</div>

I am no Flask expert, but most, if not all TCP based (HTTP) servers have a timeout setting. With most HTTP servers it defaults to 30 seconds. Try looking for where you can set that to the time you require

---

<div class="post-metadata">

**Author:** ![Michael\_Birkeland](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/michael_birkeland/32/560_2.png) [@Michael\_Birkeland](https://community.crewai.com/u/Michael_Birkeland)\
**Post date:** [November 16, 2024, 7:43pm UTC](https://community.crewai.com/t/flask-and-crewai/1122/3 "2024-11-16T19:43:56Z")

</div>

Hi guys. And @Dabnis - I was actually trying to DM you about almost this very problem. I’ve scoured the internet, and I can’t seem to find any reasonable way to deploy my crew so that I can call it with requests 🤷🏻‍♂️ Do you have any resources to point me to?

---

<div class="post-metadata">

**Author:** ![Dabnis](https://avatars.discourse-cdn.com/v4/letter/d/858c86/32.png) [@Dabnis](https://community.crewai.com/u/Dabnis)\
**Post date:** [November 16, 2024, 7:49pm UTC](https://community.crewai.com/t/flask-and-crewai/1122/4 "2024-11-16T19:49:51Z")

</div>

Hi @Michael_Birkeland ,  
Does [this](https://discuss.python.org/t/flask-request-timeouts/10734) help?

As far as I know Flask is the only viable option for a Python based server.

Get back to me.

Regards.  
Dab

Update:  
Also take a look [here](https://community.render.com/t/increase-flask-service-timeout-limit/1664) that points to [these settings](https://docs.gunicorn.org/en/stable/settings.html#timeout). It seems that if you set timeout to 0, it disables timeouts 🙂

To do it without Flask: I would set up a simple Nginx HTTP server, dockerise your Python/CrewAI and proxy the API requests from Nginx → dockerised .  
You could just expose your HTTP port value on the docker container and allow the API requests from Nginx to route to the docker container directly.

---

<div class="post-metadata">

**Author:** ![Michael\_Birkeland](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/michael_birkeland/32/560_2.png) [@Michael\_Birkeland](https://community.crewai.com/u/Michael_Birkeland)\
**Post date:** [November 16, 2024, 8:02pm UTC](https://community.crewai.com/t/flask-and-crewai/1122/5 "2024-11-16T20:02:35Z")

</div>

Woah! That was quick @Dabnis 😅 I am about to expose my noobness.

I like to code. I’m a decent hobby developer. However, I’m woefully lacking in things that are more “production” related. Like deploying stuff. Making sure dependencies are ok. Installing libraries in environments… So right now I’m really struggling to take my crew and put it somewhere where I can go to [https://somedomain.com/api/crew/run-something](https://somedomain.com/api/crew/run-something), pass it a request body and have it return something. (Setting the timeout would’ve been an issue though, and now I learned how to resolve that 🙏🏻)

It seems like Flask is the way to go, but it is not obvious to me what service I should use to deploy it 🤷🏻‍♂️

---

<div class="post-metadata">

**Author:** ![Dabnis](https://avatars.discourse-cdn.com/v4/letter/d/858c86/32.png) [@Dabnis](https://community.crewai.com/u/Dabnis)\
**Post date:** [November 16, 2024, 8:10pm UTC](https://community.crewai.com/t/flask-and-crewai/1122/6 "2024-11-16T20:10:04Z")

</div>

Hi Michael\_Birkeland,  
My advice is this:  
Larn how to set-up a Flask server with endpoints that you can call locally on your box. [Search youtube](https://www.google.com/search?q=youtiube%3A+setup+Flask+locally&client=firefox-b-d&sca_esv=2ed73cc1c03bd200&ei=scw4Z9DnNsKfhbIPuZ3qiQI&ved=0ahUKEwiQhJaLp-GJAxXCT0EAHbmOOiEQ4dUDCA8&uact=5&oq=youtiube%3A+setup+Flask+locally&gs_lp=Egxnd3Mtd2l6LXNlcnAiHXlvdXRpdWJlOiBzZXR1cCBGbGFzayBsb2NhbGx5MggQABiABBiiBDIIEAAYgAQYogQyCBAAGIAEGKIEMggQABiABBiiBDIIEAAYogQYiQVIrFtQngZYhFZwAXgBkAEBmAHyA6ABlxaqAQgyNC40LjQtMbgBA8gBAPgBAZgCHKAClxLCAgoQABiwAxjWBBhHwgILEAAYgAQYkQIYigXCAhEQLhiABBixAxjRAxiDARjHAcICDRAuGIAEGLEDGEMYigXCAgsQABiABBixAxiDAcICCxAuGIAEGLEDGIMBwgIIEC4YgAQYsQPCAggQABiABBixA8ICFhAuGIAEGLEDGNEDGEMYgwEYxwEYigXCAg0QABiABBixAxhDGIoFwgIQEAAYgAQYsQMYQxiDARiKBcICChAAGIAEGEMYigXCAgUQLhiABMICBRAAGIAEwgINEAAYgAQYsQMYgwEYCsICChAAGIAEGLEDGArCAgoQABiABBixAxgNwgIHEAAYgAQYDcICChAAGIAEGMcDGA3CAgcQIRigARgKwgIIEAAYCBgNGB7CAgsQABiABBiGAxiKBcICBBAhGBWYAwCIBgGQBgiSBwQyNC40oAfTswE&sclient=gws-wiz-serp).  
Then search [youtube](https://www.google.com/search?q=youtiube%3A+setup+Flask+locally+with+API+endpoints&client=firefox-b-d&sca_esv=2ed73cc1c03bd200&ei=Tvs4Z46hOpilhbIP1-u5oQ0&ved=0ahUKEwiOgKbF0-GJAxWYUkEAHdd1LtQQ4dUDCA8&uact=5&oq=youtiube%3A+setup+Flask+locally+with+API+endpoints&gs_lp=Egxnd3Mtd2l6LXNlcnAiMHlvdXRpdWJlOiBzZXR1cCBGbGFzayBsb2NhbGx5IHdpdGggQVBJIGVuZHBvaW50czIHECEYoAEYCki_NFC2BVilKXABeAGQAQCYAXygAa0NqgEEMTUuNLgBA8gBAPgBAZgCFKACzA3CAgoQABiwAxjWBBhHmAMA4gMFEgExIECIBgGQBgiSBwQxNS41oAfhSA&sclient=gws-wiz-serp) for how to set up API endpoints on your local Flask server.  
It will be great fun and you will learn 99% of what you will need to know to set the same up on a cheap [DigitalOcean](https://www.digitalocean.com/) droplet, about $6/month.

\*\*REM: I’m a Python noob myself, more Golang/Rust/C++, etc.

---

<div class="post-metadata">

**Author:** ![Michael\_Birkeland](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/michael_birkeland/32/560_2.png) [@Michael\_Birkeland](https://community.crewai.com/u/Michael_Birkeland)\
**Post date:** [November 16, 2024, 8:12pm UTC](https://community.crewai.com/t/flask-and-crewai/1122/7 "2024-11-16T20:12:38Z")

</div>

Alright @Dabnis💪🏻 Challenge accepted. I spent some hours on this yesterday and went to bed feeling so useless. But The gauntlet has been thrown. Once I get it working I’ll make a video for others like me 😉

---

<div class="post-metadata">

**Author:** ![Michael\_Birkeland](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/michael_birkeland/32/560_2.png) [@Michael\_Birkeland](https://community.crewai.com/u/Michael_Birkeland)\
**Post date:** [November 16, 2024, 9:31pm UTC](https://community.crewai.com/t/flask-and-crewai/1122/8 "2024-11-16T21:31:50Z")

</div>

Ok. So, quick update @Dabnis :  
I was able to get a skeleton Flask app up and running on Vercel (which I really like). [https://fa-02.vercel.app/](https://fa-02.vercel.app/)

Then I installed crewai using pip and added those to the requirements.txt

I have two questions or topics to discuss:

1. I think it may fail because my repo is now more than 300 mb of sheer dependencies. And I believe this will fail with on Hobby plan.
2. Surely, I cannot be the only person in the world to run large apps like this? How do people usually handle large amounts of dependencies? Do you reference them externally?

---

<div class="post-metadata">

**Author:** ![web3\_nk](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/web3_nk/32/1019_2.png) [@web3\_nk](https://community.crewai.com/u/web3_nk)\
**Post date:** [November 17, 2024, 5:09am UTC](https://community.crewai.com/t/flask-and-crewai/1122/9 "2024-11-17T05:09:10Z")

</div>

I did create the app with same idealogy

On flask route i called the crew ai function that makes it run

---

<div class="post-metadata">

**Author:** ![Dabnis](https://avatars.discourse-cdn.com/v4/letter/d/858c86/32.png) [@Dabnis](https://community.crewai.com/u/Dabnis)\
**Post date:** [November 17, 2024, 9:38am UTC](https://community.crewai.com/t/flask-and-crewai/1122/10 "2024-11-17T09:38:15Z")

</div>

Hi Michael\_Birkeland,  
The issue is Python, not you or your app. I have often wrote on this discord: “Python is holding AI hostage”.  
300Mb is not bad for a Python app, I’ve seen many that are 1Gb+!. \*\*REM a similar app in such as Go, Rust, etc will be 10-20 Mb.  
I still maintain that getting what you want working on your box locallyy is the way to go for you as any online deployment is going to cost you, and cost you more because it’s Python.  
FYI: I build my own AI applications in Go and Rust because of all of these Python issues.  
Everybody on this discord should know and understand: Python as originally created was a ‘scripting’ language, used primarily by data scientist’s. It was never meant to be a full blown software language in the same realm as c,C++, Go, Rust.  
Many will see my views as those of an old guy who has been a software engineer for 50+ years, but I stand by all that I have wrote above. Time to get off my ‘soap-box’.  
So why has Python get to where it is? Humans are lazy by design, it started with the wheel and continues today. If you can just use a library/package with just a few clicks then people will. The downside is that you learn nothing and inherit all of the issues that Python gives people trying to work with AI today with Python.

Having said all of the above, I still believe that your best route is to get something working on your local box. You will learn key skills. After that, look at learning a software language, it’s not hard and it will open up oportunities for you that could change the hrest of your life.

If I knew more about Python Michael I would offer to help you. For now all I can give is the advice above.

Best of luck.  
Dab

---

<div class="post-metadata">

**Author:** ![Michael\_Birkeland](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/michael_birkeland/32/560_2.png) [@Michael\_Birkeland](https://community.crewai.com/u/Michael_Birkeland)\
**Post date:** [November 17, 2024, 10:11am UTC](https://community.crewai.com/t/flask-and-crewai/1122/11 "2024-11-17T10:11:38Z")

</div>

🧼📦!

Thanks @Dabnis  
I’m an older guy myself (although, perhaps a few years younger than you). Experience is undervalued 🙋🏻‍♂️

I’m currently running the Flask app locally, but how would I make sure the endpoint is accessible to the world? I’m going to investigate and let you know what I come up with 😉

Perhaps I’ll finally take the plunge and learn a real programming language

Thanks for taking the time Dab 🙏🏻

---

<div class="post-metadata">

**Author:** ![Dabnis](https://avatars.discourse-cdn.com/v4/letter/d/858c86/32.png) [@Dabnis](https://community.crewai.com/u/Dabnis)\
**Post date:** [November 17, 2024, 10:16am UTC](https://community.crewai.com/t/flask-and-crewai/1122/12 "2024-11-17T10:16:50Z")

</div>

Hi Michael,  
The easiest route to getting your app online is to learn how to containerise, make a docker image of it. Then you can deploy that container onto a cloud based server, like DigitalOcean as a docker container.  
Here’s your [YouTube search](https://www.google.com/search?client=firefox-b-d&q=youtube+making+a+docker+container+from+a+Python%2C+flask+app)

Let me know how you get on, I’ll continue to help where I can.

Best of luck 🙂  
Dab

---

<div class="post-metadata">

**Author:** ![Dabnis](https://avatars.discourse-cdn.com/v4/letter/d/858c86/32.png) [@Dabnis](https://community.crewai.com/u/Dabnis)\
**Post date:** [November 17, 2024, 10:20am UTC](https://community.crewai.com/t/flask-and-crewai/1122/13 "2024-11-17T10:20:30Z")

</div>

Once you get your app containerised, here’s your [YouTube search](https://www.google.com/search?q=youtube+how+to+deploy+a+docker+conatiner+on+DigitalOcean&client=firefox-b-d&sca_esv=804146835f2e9699&ei=VMI5Z7fBO6vBhbIPy9uimAM&ved=0ahUKEwi3u5SskeOJAxWrYEEAHcutCDMQ4dUDCA8&uact=5&oq=youtube+how+to+deploy+a+docker+conatiner+on+DigitalOcean&gs_lp=Egxnd3Mtd2l6LXNlcnAiOHlvdXR1YmUgaG93IHRvIGRlcGxveSBhIGRvY2tlciBjb25hdGluZXIgb24gRGlnaXRhbE9jZWFuMgcQIRigARgKMgcQIRigARgKMgcQIRigARgKMgYQIRgVGApIhYEBUABYhXxwAHgBkAEAmAF2oAHIGKoBBDM5LjO4AQPIAQD4AQGYAiqgApcZwgILEAAYgAQYkQIYigXCAgYQABgHGB7CAgUQABiABMICCBAAGIAEGLEDwgILEC4YgAQYsQMYgwHCAgsQABiABBixAxiDAcICERAAGIAEGJECGLEDGIMBGIoFwgIGEAAYFhgewgIIEAAYgAQYogTCAggQABiiBBiJBcICBRAhGKABwgIEECEYFcICBRAhGJ8FmAMAkgcEMzkuM6AHkZ8C&sclient=gws-wiz-serp) on how to deploy it to DigitalOcean (by far the cheapest option)

\*\*REM: Todays is the first day of the rest of your life, imagine what you could achieve if you put your mind to it 🙂

Dab

---

<div class="post-metadata">

**Author:** ![Dabnis](https://avatars.discourse-cdn.com/v4/letter/d/858c86/32.png) [@Dabnis](https://community.crewai.com/u/Dabnis)\
**Post date:** [November 17, 2024, 10:26am UTC](https://community.crewai.com/t/flask-and-crewai/1122/14 "2024-11-17T10:26:10Z")

</div>

Hi Michael,  
here’s you [YouTube search](https://www.google.com/search?q=Youtube%3A+how+to+expose+API+endpoints+with+Fask&client=firefox-b-d&sca_esv=804146835f2e9699&ei=7MI5Z8HyErq3hbIPt6aV0AY&ved=0ahUKEwjBmKn0keOJAxW6W0EAHTdTBWoQ4dUDCA8&uact=5&oq=Youtube%3A+how+to+expose+API+endpoints+with+Fask&gs_lp=Egxnd3Mtd2l6LXNlcnAiLllvdXR1YmU6IGhvdyB0byBleHBvc2UgQVBJIGVuZHBvaW50cyB3aXRoIEZhc2syBRAhGKABMgUQIRigATIFECEYoAEyBRAhGKABSP9wUABYn21wAHgAkAEAmAGJAqABjByqAQY0MS4yLjG4AQPIAQD4AQGYAiygAtUcwgIWEC4YgAQYsQMY0QMYQxiDARjHARiKBcICCxAAGIAEGJECGIoFwgIREC4YgAQYsQMY0QMYgwEYxwHCAgsQABiABBixAxiDAcICCxAuGIAEGLEDGIMBwgIIEC4YgAQYsQPCAggQABiABBixA8ICChAAGIAEGEMYigXCAhAQLhiABBixAxhDGIMBGIoFwgIQEAAYgAQYsQMYQxiDARiKBcICDRAAGIAEGLEDGEMYigXCAhAQLhiABBjRAxhDGMcBGIoFwgIFEAAYgATCAgYQABgWGB7CAggQABgWGAoYHsICCBAAGIAEGKIEwgIEECEYFcICBxAhGKABGAqYAwDiAwUSATEgQJIHBjQwLjMuMaAHydYB&sclient=gws-wiz-serp) on how to expose Flask API endpoints

Regards.  
Dab
