Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python request module vs. urllib.request vs. javascript with JQuery/ajax In Production Environment [closed]

I am writing a small program that consumes an API. The program is using Python with requests JSON and requests module. it makes a HTTP request and the API returns a json data. Then I will do something to the data.

it looks like this.

import json, requests

url = 'http://maps.googleapis.com/maps/api/directions/json'
params = {...}

resp = requests.get(url=url, params=params)
data = json.loads(resp.text)
#do something with data

However, I start to wonder about 3 specific questions about my choice of language and design:

  1. Currently, It is obvious that I am the only one using this program but eventually if I publish this program that means more than one people will be using it. Should my choice of language and module differ when it comes to production environment?

  2. why should I use the request module, why not urllib.request module? urllib module can also make http request.

  3. Furthermore, why use Python? I am using Python because I am familiar with it. Maybe I can use this chance to learn JavaScript. I can use JQuery and AJAX to accomplish the same thing. Is there a better way? or it depends on what the program is for?

Any explanation is appreciated.


Bonus: This following question is broad so I don't expect the chosen answer to include for the following questions but it will be nice.

There are much more great languages, modules, and library that can be used to accomplish my desired task. Basically is there a best way to request JSON data from an API? or it depends on the circumstances? if so, how do circumstances should affect the choice of language and design? and what are the pros and cons?

like image 634
J.Doe Avatar asked Nov 07 '22 17:11

J.Doe


1 Answers

  1. Requests makes your life easier. Not by much in this case, but try writing the same thing using urllib2
  2. You can use any language of your choice. If you intend to make this into some kind of a CLI or GUI, then JS will probably be better because your final application can then live at a web address. Or you can make a nice App using Kivy or CLICK and distribute it as a binary
  3. Problems with multiple connections is a lookout for the server, not your app. The stack that you use for the backend will be the deciding factor that makes or breaks your app, not how many people end up using it simultaneously.
like image 198
Mortz Avatar answered Nov 14 '22 23:11

Mortz