We’re running a Python FastAPI service with ~40 dependencies (including aiohttp, Flask-Cors, pymongo, etc.) on Vercel and facing long deployment times (10-15 minutes) due to package reinstallation on every deploy. Our dependencies rarely change between deployments, so reinstalling all packages each time seems inefficient.
Current situation:
~40 Python packages with specific versions pinned
Each deployment takes 10-15 minutes, mostly spent on package installation
Dependencies rarely change between deployments
Build cache shows only “29.00 B” being uploaded, suggesting the Python package cache isn’t being preserved
Using Python 3.12 runtime
We’ve tried:
Using pip’s cache directory (–cache-dir)
Configuring custom install commands in vercel.json
Various .vercelignore configurations to preserve cache
Setting up wheel directories
Using Pipfile/Pipfile.lock instead of requirements.txt
Is there a recommended way to cache Python packages between deployments?
Is there a difference in caching behavior between requirements.txt and Pipfile approaches?
Are there specific directories we should be caching for Python projects?
Should we be using a different build command or configuration for optimal caching?
Do certain Python package types (wheels vs source distributions) cache better than others?
Other frameworks (Node.js, etc.) seem to have built-in caching support, but we haven’t found clear documentation for Python projects. Our goal is to reduce deployment times by reusing previously installed packages when dependencies haven’t changed.
Any guidance on best practices for Python package caching would be greatly appreciated. We’re open to restructuring our project or changing our dependency management approach if it would help with caching.
Vercel automatically caches dependencies for Python projects . For best results, use a requirements.txt file in your project’s root directory with pinned package versions. So it’s better to stick with requirements.txt rather than Pipfile for optimal caching performance on Vercel.
You don’t need to manually specify cache directories; Vercel handles this automatically for Python projects .
The default install command pip install -r requirements.txt should work well in most cases.
Remember, the build cache has a maximum size of 1 GB and is retained for one month. If you’re still facing issues after implementing these suggestions, don’t hesitate to reach out to Vercel support for more specific guidance.
I hope this helps streamline your deployment process! Let me know if you have any other questions.
I’m now wondering if we have an issue with our project structure, seeing as the build cache has only ever shown 29.00 B being uploaded (whereas we’d expect 50-100mb based on our dependencies).
Do you see anything wrong with our project structure and/or vercel.json? I appreciate your help – Vercel is new to us, and we’re enjoying it so far!