HomeОбразованиеRelated VideosMore From: CodingEntrepreneurs

Coding With Python :: Learn API Basics to Grab Data with Python

3341 ratings | 432041 views
Coding With Python :: Learn API Basics to Grab Data with Python This is a basic introduction to using APIs. APIs are the "glue" that keep a lot of web applications running and thriving. Without APIs much of the internet services you love might not even exist! APIs are easy way to connect with other websites & web services to use their data to make your site or application even better. This simple tutorial gives you the basics of how you can access this data and use it. If you want to know if a website has an api, just search "Facebook API" or "Twitter API" or "Foursquare API" on google. Some APIs are easy to use (like Locu's API which we use in this video) some are more complicated (Facebook's API is more complicated than Locu's). More about APIs: http://en.wikipedia.org/wiki/Api Code from the video: http://pastebin.com/tFeFvbXp If you want to learn more about using APIs with Django, learn at http://CodingForEntrepreneurs.com for just $25/month. We apply what we learn here into a Django web application in the GeoLocator project. The Try Django Tutorial Series is designed to help you get used to using Django in building a basic landing page (also known as splash page or MVP landing page) so you can collect data from potential users. Collecting this data will prove as verification (or validation) that your project is worth building. Furthermore, we also show you how to implement a Paypal Button so you can also accept payments. Django is awesome and very simple to get started. Step-by-step tutorials are to help you understand the workflow, get you started doing something real, then it is our goal to have you asking questions... "Why did I do X?" or "How would I do Y?" These are questions you wouldn't know to ask otherwise. Questions, after all, lead to answers. View all my videos: http://bit.ly/1a4Ienh Get Free Stuff with our Newsletter: http://eepurl.com/NmMcr The Coding For Entrepreneurs newsletter and get free deals on premium Django tutorial classes, coding for entrepreneurs courses, web hosting, marketing, and more. Oh yeah, it's free: A few ways to learn: Coding For Entrepreneurs: https://codingforentrepreneurs.com (includes free projects and free setup guides. All premium content is just $25/mo). Includes implementing Twitter Bootstrap 3, Stripe.com, django south, pip, django registration, virtual environments, deployment, basic jquery, ajax, and much more. On Udemy: Bestselling Udemy Coding for Entrepreneurs Course: https://www.udemy.com/coding-for-entrepreneurs/?couponCode=youtubecfe49 (reg $99, this link $49) MatchMaker and Geolocator Course: https://www.udemy.com/coding-for-entrepreneurs-matchmaker-geolocator/?couponCode=youtubecfe39 (advanced course, reg $75, this link: $39) Marketplace & Dail Deals Course: https://www.udemy.com/coding-for-entrepreneurs-marketplace-daily-deals/?couponCode=youtubecfe39 (advanced course, reg $75, this link: $39) Free Udemy Course (40k+ students): https://www.udemy.com/coding-for-entrepreneurs-basic/ Fun Fact! This Course was Funded on Kickstarter: http://www.kickstarter.com/projects/jmitchel3/coding-for-entrepreneurs
Html code for embedding videos on your blog
Text Comments (289)
Nicachipal (8 days ago)
How do you access an attribute inside a dictionary ? Imagine you had : "objects":[{ "fullname":[{"@name":"John", "last_name":"Doe"}] "locality":"Newport Beach" ..... and so on ... }] Thank you in advance !!!!
Nicachipal (7 days ago)
CodingEntrepreneurs by the way I forgot to mention that I did the iteration in views, and it works, but in the template I only get the last element of all the objects. For example if I have four names (John, Matt, Douglas, Tom) the output I get is only Tom. Maybe I am doing something wrong. Thank you !
Nicachipal (7 days ago)
CodingEntrepreneurs I watched one of your videos where you say not to do the iteration in views but in the template instead. However, I did the iteration in views to clean the data, but when I try to render it in the template I only get the last element of that iteration. And that is exactly what you said in that video, unless I miss understood you and there is a different way to do this. Would you please email ([email protected]) me if it is easier for you to respond to my question. Thank you so much ! You are a great teacher !
CodingEntrepreneurs (8 days ago)
Do the iteration in the view instead of the template to clean the data, then render to the template
Nicachipal (8 days ago)
+CodingEntrepreneurs Thanks for the quick response. One more last question. I am trying to display those attributes ("@name" and "last_name") elements on a template in django. I can easy display "locality" and iterate through all those objects. This is my approach: In views.py I have : r = requests.get(url).json() search = r[objects] context = { 'search':search} template = 'home.html' return render(request, template, context) in home.html template I have : {% for list in search %} {{ list.locality.0 }} {% endfor %} I don't know how to access the attributes from here (from the template). If i do {{ [email protected] }} I get an error message because of this "@" character. How can I escape that ?
CodingEntrepreneurs (8 days ago)
Or iterate through all objects and do something similar
srikanth B (20 days ago)
Hi team, I appreciate your channel for taking great initiative topics which are really helpful. Here is a similar post defines main Python Basics. https://shoutmepython.com/learn-top-5-python-3-basics/
Host Promo (2 months ago)
Fantastic over view. Python and APIs are the future!
Opiyo Sebastian (4 months ago)
Thank you!
Lou Pendley (4 months ago)
No longer free Locu access. No bueno.
Nitin Nath Giri (2 months ago)
even paid too
mac lanphere (5 months ago)
nice vid! since this is a couple years old now, curious, is it more common to be using python 3.0 these days?
Ineeda Name (5 months ago)
For anyone trying to make an account after January 2017, you can't. Godaddy claimed Locu and blocked any new developer sign-ups.
Monochrome (2 months ago)
so that's why DX
"Freecodеsхxx" - Sеаrсh it on Gооgle. Yоu wіll reсеіve а lоt of frеe cоdеs.
Harini Pedarapu (7 months ago)
Can anyone provide the script for Below Requirement =====> First connect to Jenkins Server Using Rest API =====> And then list all the jobs with their names which have not been triggered from past 3 Months Right script will be awarded.......
resit k (7 months ago)
is API charge money?
SoldierGaming (7 months ago)
How did you know it was json? Is there a way to tell that information?
Aditya Sharma (9 months ago)
A NEW NOTE TO PYTHON USER If you are using urllib3 you will need these code import json import urllib3 import requests # api key locu_api = '9fb8cd70cb34cab8e83690473133f51943b5c93f' def locu_search(query): # copying the key api_key = locu_api # adding to url url = 'https://api.locu.com/v1_0/venue/search/?api_key=' + api_key # defining some space locality = query.replace(' ', '%20') # adding final data to url final_url = url + "&locality=" + locality + "&category=restaurant" response = requests.get(final_url) data=response.json() # displaying it to user for item in data['objects']: print(item['name'], item['phone']) x = input('Enter your location:') locu_search(x) i modified it a little if you have any query check out this link https://stackoverflow.com/questions/25189895/error-when-trying-to-use-urllib3-json-to-get-rotten-tomatoes-data-python
NvStar Karaoke (9 months ago)
Michael Archer (9 months ago)
Trying to trap people into subscribing with that video layout made me not want to watch the rest...
TheCreativeMale (10 months ago)
https://dev.locu.com doesn't have a join button anymore. I've emailed them and had no response.
TheCreativeMale (10 months ago)
Will you be doing an updated video ? This one is very good and really helped me, as I have to learn Python as my core programming language and need to make API calls to different monitor systems, so found your video very helpful to understand how to read the data into sets. Thank you
CodingEntrepreneurs (10 months ago)
Yeah locu is not working anymore. Check out the Yelp API. A lot of the concepts overlap to this vid
TheCreativeMale (10 months ago)
scrub that, their site seems to be not complete, as loads of go daddy messages of page not found
TheCreativeMale (10 months ago)
ok you need to go to the press part of their web page... https://locu.com/press/ and join us is in the top right
Giga (11 months ago)
Great video
Bkheang (11 months ago)
How do you pass an API as a header.
Congratulations!!! Excellent tutorial!!!
Bkheang (11 months ago)
what is urllib2?
Benjamin Nitro (11 months ago)
cool and helpful
Andreana Stl (11 months ago)
Thank you for your videos! I am currently looking for some way to download and save locally an api data-set, so that I can then put it in an sql database. I tried using python 3's urllib.request, but the data-set is too big (900 json pages) and has a "links" object on each page with 2 links inside (self and next). Is there a way that i can download the entire data set with python code? I hope that my question makes sense. Any help would be greatly appreciated!
Javier D. (11 months ago)
I can't make an account, there's only an option to login and reset my password. Any help?
Butcher (1 year ago)
instead of printing it can i return a dynamic object constructed from the api response?
jwuj97f (1 year ago)
Great presentation. The speed and examples were perfect. The way you walked through the content and concepts is exactly the way I learn best. Again great job! I look forward to your next video.
Chandrasekhar Baruva (1 year ago)
Awesome tutorial....step by step explanation n execution , it's a great teaching method and easy to understand.
bhawani singh (1 year ago)
i need your help on a python kivy application development. i am creating an application using python and kivy where i want to authenticate user through instagram. when the user authenticate himself with instagram then instagram api redirect my user to a redirect_uri with access token in the browser but i want my application to grab this access token . how can i do this . please help me with this
Hexiarmin (1 year ago)
Hi. Thank you. I am trying to create a type of information query system for my web research. Is the API method you show similar to what a web crawler would do? (Just That API uses a already set interface with websites?) Can I combine the web scraping and this API query method in some way?
Michele Angrisano (1 year ago)
Could you give me the name of font of Komodo? Thanks
The Artful Dodger (1 year ago)
PYTHON is slow. PHP is fast. The choice is yours.
Yogesh Arora (1 year ago)
Awesome content
Glenn Martin (1 year ago)
I never watch these videos because of a short attention span but this was the only tutorial I could find after searching multiple forums/articles that came close to what I needed to understand how to deal with a problem I was having with a complicated return list I've been trying to parse. Thanks. Thumbs up to you.
CodingEntrepreneurs (1 year ago)
Thank you! Cheers
Zakaria Belgoum (1 year ago)
i love you man
dr kreiger (1 year ago)
Fantastic video!!! Have very little experience with REST API's and JSON but I found exactly what I need easily within the 5 minute mark.
dr kreiger (1 year ago)
I will also add that I was not even using the same api
Mark Hives (1 year ago)
Annoying adverts at the bottom which can't be closed. I stopped watching after 20 seconds
Navjot Singh (1 year ago)
Mark Hives just get an ad blocker i have and not seeing any ads
Vijay Gharge (1 year ago)
Very well explained. Good for people having prior python experience...
Mohammed Salih (1 year ago)
How do you create an account?
nabadeep mitra (1 year ago)
Best API basics with Python found so far
Pablo God (1 year ago)
Thank you!
Vaping Guys (1 year ago)
Locu developer registration is shut down by GoDaddy in January 2017
Qiu Tyrion (1 year ago)
Thanks, great help!
uday kumar maddi (1 year ago)
how can we authenticate using basic auth in python
Soumya Bose (1 year ago)
you are a rockstar man ...i am a absolute beginner...and made me understand api and grabbing data with python.keep up the good work
CodingEntrepreneurs (1 year ago)
Awesome! Great to hear it
sparsh bijawat (1 year ago)
Is this way to get the content from any other website like Walmart and ebay to get the content through API's?
qyie (1 year ago)
cant sign up to locu api?
Navjot Singh (1 year ago)
seth it’s shut down now
parth shah (1 year ago)
locu registration is closed.. :( are there any other alternatives?
Raj GJ (1 year ago)
good one, easy to understand. thanks dude
Walt Reed (1 year ago)
Awesome video, thank you so much!
CodingEntrepreneurs (1 year ago)
Ravi Teja (1 year ago)
This is what I am looking for..Great video.
Rosa Soria (1 year ago)
I am a beginner and this was super useful, thank for sharing! Locu does not work anymore, does anyone want to join me in playing with the brewerydb API, instead?
CodingEntrepreneurs (1 year ago)
+Rosa Soria thanks!
Rashele Shoun (1 year ago)
This is a really helpful video. Do you think you could do one with xml, specifically raw xml that has no schema?
Ehsan Jehangir (1 year ago)
i'm working on a restuarant review web project and i cant show comments given by users on the profile page of a particular restuarant . the comment, user profile name and profile pic has to be fetched from the database. i'm using flask. any tutorial for viewing user comments on a profile page ??
CodingEntrepreneurs (1 year ago)
+Ehsan Jehangir we don't use flask sorry!
Ro (1 year ago)
CodingEntrepreneurs (1 year ago)
+Robert Balaile thanks!
John Mahugu (1 year ago)
thank you so much :) i have been looking for this for a very long time, i have a specific question to ask you please email me
in2mindstation (2 years ago)
Thank you! I did not expect to learn APIs this fast. Fantastic, concise tutorial.
kartikey srivastava (2 years ago)
You're awesome. Thanks for sharing, really appreciate the effort :)
James Koene (2 years ago)
How do I access the API?
Shreya (2 years ago)
I cant sign up for LOCU..there are some issues I am facing..I am sure LOCU is a paid service.I cant sign up as Icon itself of signup doesn't show up when i open it.Can you guys help me please to get url?? i can get API key but getting URL is problem..Can you suggest how can i do it??I need to scrape data from website..
Shwe Linlin (1 year ago)
+shre"/?ya priya
Ashish Veer Singh (2 years ago)
oh fine actually i have a need of api coder in Python
Shreya (2 years ago)
+Ashish Veer Singh not much..I have recently started
Ashish Veer Singh (2 years ago)
shreya priya hey i just wanna knw do u regular in Python coding ? For api development . plz let me know asap
Nikhil Rao (2 years ago)
Great Video.. Is there a way to sign up for Locu API?. I guess they removed the sign Up button in their page.
tosh noway (2 years ago)
your keyboard sounds amazing btw.
jamesT008 (2 years ago)
Thanks...nice one!!
DagsKoopa (2 years ago)
This was phenomenal! Thank you very much
sparsh bijawat (2 years ago)
np.apply along axis? What is the use of this statement? and how to use it?
Amogh Halageri (2 years ago)
I'm new to Python, and I was doing codes on Java before. I can see that Python is simpler than Java, however I can't find a Python equivalent to this website of Java: https://docs.oracle.com/javase/7/docs/api/. I could find all codes, classes and packages in one place and stay updated with the changes. The docs provided on Python website is too pedantic, and not as well organized as docs.oracle.com. So, how do you guys actually find Python codes, classes or packages for specific tasks without something like docs.oracle.com?
Amogh Halageri (2 years ago)
Thank you!
Hi Amogh. have you tried the Python Project Documentation? Here https://www.python.org/doc/ you can find the documentation describing everything you're asking for. Additionally you'll find resources you can use and learn from.
Scott Koons (2 years ago)
Great video! Anything for Yelp APIs?
Brandon Lipman (2 years ago)
Your tutorials are insanely great. Thank you. Do you have any videos that go over how to take data like what you got here or like what you did with YellowPages and put it in a CSV file?
Jesse C S Ulundo (2 years ago)
Wonderful tutorial it's helping me a lot with my research... I was wondering if you could explain how to extract this data to cvs file for data analysis with R. Once again thanks so much
Spoodily (2 years ago)
Mind blown. Great video on many different levels. So much info in 20 minutes. Thank you.
Khaled Elnagar (2 years ago)
Very interesting. I am in love with Python.
Larry Tsai (2 years ago)
is it okay for you to be showing everyone your API key?
Smiley Guy (2 years ago)
That dah-tah is driving me crazy
Val Stafford (2 years ago)
the gold is in the land to coding with python
Ger Her (2 years ago)
Grab her by the API! ;)
SAGAR SAURABH (1 year ago)
tats geekish way of harr==>@ss!!ng
Christopher Simmons (1 year ago)
Ger Her
Anton Nig (1 year ago)
Clever Programmer go away bitch you dogged codecademy
adtrawka (2 years ago)
Wrong! Make a request to her and in response she might show you her API! ;)
Clever Programmer (2 years ago)
Yukun Liu (2 years ago)
Hi, I can't sign up at Locu.com anymore.
icketypickety (9 months ago)
search for jsonPlaceholder gives u api for mock data
DSYNC (1 year ago)
That sucks
Abang Jalan2 (1 year ago)
Xan Don (1 year ago)
go daddy shut the locu api signup :(
Nikhil Rao (2 years ago)
I created a account in repl.it. And i Got the secret key. Can you tell me how to use it.?
Scientific Stevie (2 years ago)
I got a python ad
ZABER CORP. (2 years ago)
Amazing tutorial video.
CodingEntrepreneurs (2 years ago)
Thanks for watching!
Pavan Nayakanti (2 years ago)
This is in the benefit of those who are facing conflicts with versions of urllib... import urllib.request as ur import urllib.parse as par import json #url = 'https://api.locu.com/v1_0/venue/search/?locality=Noida&api_key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' locu_api = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' def locu_search(query): api_key = locu_api url = 'https://api.locu.com/v1_0/venue/search/?api_key=' + api_key locality = query.replace(' ','%20') final_url = url + "&locality=" + locality html = ur.urlopen(final_url).read() data = json.loads(html.decode('utf-8')) for item in data['objects']: print (item['name'],item['locality'],item['phone'])
aldan brito (2 years ago)
how to do a post using locu app???
Vasiliy D (2 years ago)
Cool, but python3 does not let to use urllib2 Will looking for another method. thank you
Mini-Me Development (2 years ago)
+CodingEntrepreneurs Wouldn't it be better to use urllib.urlencode for what you are doing manually?
Beto Mendez (2 years ago)
Great video.
Vaibhav Ahuja (2 years ago)
thanks :D
BillyBob Pango (2 years ago)
5:13 That brainfart was bigger than the one i had watching this video
It's really AWESOME man !!!
Siva Srimakurthi (2 years ago)
very detailed explanation and well planned video. I loved it. thanks a million for the brilliant video.
Ashish Karel (2 years ago)
Changing locality is fine but what should we do if we want to change our country.Thank you.
渝泽马 (2 years ago)
thx for the video first, but um.....why am I failed at print each separately? after I type in print item , then it stays there
Pradyumna Majumder (2 years ago)
Absolutely amazing video!!! Loved it!! :) Thanks alot.
Taylor Lee (2 years ago)
I fellow the video and did my first grabbing data process. I think I learnt a lot from the video and now I have confidence to do more.
Jose Hernandez (2 years ago)
thank you so much! great vid! A NOTE FOR PEOPLE USING PYTHON 3.5: import urllib.request you would have to use urllib.request.urlopen(url).read() instead of urllib2.urlopen(url) and you would have to convert it into a string like so response = urllib.request.urlopen(url).read() json_obj = str(response, 'utf-8') then use json.loads instead of json.load. load did not work for me. data = json.loads(json_obj)
cuelholima (2 months ago)
Do you guys know how to filter the results? like I want to filter for id cuz I don't wanna show all the products at the same time.
Jordan Garcilla (3 months ago)
I am using this for my A Level Coursework! Thank you so much!!
Darshil D (1 year ago)
Learnhall (1 year ago)
Thank you, Jose. You're awesome. It works on 3.6.1 for me on my Mac.
sparsh bijawat (1 year ago)
>>> req = urllib.request.urlopen('http://api.walmartlabs.com/v1/search?query=ipod&format=json&categoryId=5438&apiKey=r2pxcm4cfyhmwdgrh98n44by') .read() >>> obj=str(req,'utf-8') >>> data=json.load(obj) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Anaconda3\lib\json\__init__.py", line 265, in load return loads(fp.read(), AttributeError: 'str' object has no attribute 'read' My python version is 3.5 and am getting this error constantly!!
araa (2 years ago)
how to print all the keys (instead of values)?
Siva Srimakurthi (2 years ago)
+Swaviman Kumar great! questioning is the best way to learn. All the best.
Swaviman Kumar (2 years ago)
+Siva Srimakurthi Thank you. Now I am clear. I am a newbie, so....
Siva Srimakurthi (2 years ago)
+Swaviman Kumar I just looked at the Jason file used in this example. the array name here is 'object' that is the reason we used that variable name in our example. hope this explains.
Siva Srimakurthi (2 years ago)
+Swaviman Kumar I am sure object is not a defined variable in this example, and that is the reason it's throwing nameerror. by the way can you post the trace here so we can take a look?
Swaviman Kumar (2 years ago)
if i type data['objects'] its working. but when i type data['obj'] its throwing a traceback. Why is this happening?
ajaxkm (2 years ago)
will pycharm or visual studios work too?
CodingEntrepreneurs (2 years ago)
either works!
Koevi V (2 years ago)
Awesome video, thanks!
CodingEntrepreneurs (2 years ago)
Thank you!
Tang Changguo (2 years ago)
Great video, But, How I can download these file to my local drive ?
Bruce Wayne (2 years ago)
I love you
CodingEntrepreneurs (2 years ago)
+Bruce Wayne Thank you batman. I look up to you.
mhernandez1005 (2 years ago)
Great video. Well descriptive title and to the point. http://stackoverflow.com/questions/8811269/basic-authentication-using-urllib2-with-python-with-jira-rest-api I did want to post this link for others who are trying to figure out how to access data with basic authentication. (Using a username and password instead of API key). The link also mentions python library "requests" which can take the place of urllib2. in command line: pip install requests then in your code (.py file): import requests import json r = requests.get('https://api.github.com', auth=('user', 'pass')) data = r.json()
Brazjul (2 years ago)
THANK YOU SO MUCH!! Great video! It helped me a lot! :)
Tao Li (2 years ago)
Very clear and informative. Thank you!
Hurtwolf (2 years ago)
i get the error in "for item in DATA["mature"]:" <- for twitch.tv it returns "TypeError bool object is not iterable.
CodingEntrepreneurs (2 years ago)
+Hurtwolf DATA["mature"] is a boolean (true/false) and not a list.
Sebastian Zdroana (2 years ago)
what if i created a GUI which allows the user to enter a locality or post code or w.e, how would i generate that query every time? as a new location would mean a new query
Sebastián Piedra (2 years ago)
How can I do the same with an xml format instead of json?
cuelholima (2 months ago)
+Dare Sunday I need that as well
Dare Sunday (6 months ago)
gotten an answer for this yet?

Would you like to comment?

Join YouTube for a free account, or sign in if you are already a member.