Member-only story

Why choose Python requests over Python Client for libraries?

Production AI SaaS Tips

Ramsri Goutham
2 min readJun 13, 2023
Python Client Vs Python requests

A lot of people working in Python want to use the Python Client natively. But a better option is to take the CURL code and use Python requests to call it whenever available.

Why?
If you use ‘pip install openai’ it installs libraries that are also needed for fine-tuning. If you are using it for just inference it bloats your deployment package (AWS Lambda) or anywhere you are using it in a serverless manner.

For example, if you use OpenAI for embeddings in Python, it installs many dependencies. Save on size and cold start time by using the CURL version!

Plus it may lead to library conflicts if you are using two different Python Clients let’s say one for OpenAI and one for vector Database.

Most AI libraries have a curl version which you can use via Python requests instead of Python Client.

Eg: Pinecone vector database has a curl API for all the necessary CRUD operations as well.

Across our AI apps, we have been practicing using the curl version called via Python requests library. It has been a breeze to port code (eg: OpenAI to Azure OpenAI service) with no pip install changes or other version conflicts.

Also most times Python client is behind on updates than the main API so you don’t have to wait if you are using it via curl.

Happy AI exploration and if you loved the content, feel free to find me on Twitter.

--

--

No responses yet