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

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

2963 ratings | 399692 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 (277)
Opiyo Sebastian (3 days ago)
Thank you!
Lou Pendley (17 days ago)
No longer free Locu access. No bueno.
mac lanphere (1 month 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 (1 month ago)
For anyone trying to make an account after January 2017, you can't. Godaddy claimed Locu and blocked any new developer sign-ups.
"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 (3 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 (3 months ago)
is API charge money?
SoldierGaming (3 months ago)
How did you know it was json? Is there a way to tell that information?
Aditya Sharma (5 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 (5 months ago)
THANK YOU VERY MUCH!!! U'RE THE BEST
Michael Archer (5 months ago)
Trying to trap people into subscribing with that video layout made me not want to watch the rest...
TheCreativeMale (6 months ago)
https://dev.locu.com doesn't have a join button anymore. I've emailed them and had no response.
TheCreativeMale (6 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 (6 months ago)
Yeah locu is not working anymore. Check out the Yelp API. A lot of the concepts overlap to this vid
TheCreativeMale (6 months ago)
scrub that, their site seems to be not complete, as loads of go daddy messages of page not found
TheCreativeMale (6 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 (7 months ago)
Great video
Bkheang (7 months ago)
How do you pass an API as a header.
Congratulations!!! Excellent tutorial!!!
Bkheang (7 months ago)
what is urllib2?
Benjamin Nitro (7 months ago)
cool and helpful
Andreana Stl (7 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 (7 months ago)
I can't make an account, there's only an option to login and reset my password. Any help?
Butcher (8 months ago)
instead of printing it can i return a dynamic object constructed from the api response?
jwuj97f (8 months 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 (8 months ago)
Awesome tutorial....step by step explanation n execution , it's a great teaching method and easy to understand.
bhawani singh (9 months 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 (9 months 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 (9 months ago)
Could you give me the name of font of Komodo? Thanks
The Artful Dodger (9 months ago)
PYTHON is slow. PHP is fast. The choice is yours.
Yogesh Arora (9 months ago)
Awesome content
Glenn Martin (9 months 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 (9 months ago)
Thank you! Cheers
Zakaria Belgoum (10 months ago)
i love you man
dr kreiger (10 months 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 (10 months ago)
I will also add that I was not even using the same api
Mark Hives (10 months ago)
Annoying adverts at the bottom which can't be closed. I stopped watching after 20 seconds
Navjot Singh (9 months ago)
Mark Hives just get an ad blocker i have and not seeing any ads
Vijay Gharge (11 months ago)
Very well explained. Good for people having prior python experience...
Mohammed Salih (11 months 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 (9 months 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)
Thanks!
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)
Wonderful!
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 (1 year ago)
Thank you! I did not expect to learn APIs this fast. Fantastic, concise tutorial.
kartikey srivastava (1 year ago)
You're awesome. Thanks for sharing, really appreciate the effort :)
James Koene (1 year ago)
How do I access the API?
Shreya Priya (1 year 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 (1 year ago)
oh fine actually i have a need of api coder in Python
Shreya Priya (1 year ago)
+Ashish Veer Singh not much..I have recently started
Ashish Veer Singh (1 year ago)
shreya priya hey i just wanna knw do u regular in Python coding ? For api development . plz let me know asap
Nikhil Rao (1 year 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 (1 year ago)
your keyboard sounds amazing btw.
jamesT008 (1 year ago)
Thanks...nice one!!
GoinHam121 (1 year ago)
This was phenomenal! Thank you very much
sparsh bijawat (1 year ago)
np.apply along axis? What is the use of this statement? and how to use it?
Amogh Halageri (1 year 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 (1 year 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 (1 year ago)
Great video! Anything for Yelp APIs?
Brandon Lipman (1 year 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 (1 year 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 (1 year ago)
Mind blown. Great video on many different levels. So much info in 20 minutes. Thank you.
Khaled Elnagar (1 year ago)
Very interesting. I am in love with Python.
Larry Tsai (1 year ago)
is it okay for you to be showing everyone your API key?
Smiley Guy (1 year ago)
That dah-tah is driving me crazy
Val Stafford (1 year ago)
the gold is in the land to coding with python
Ger Her (2 years ago)
Grab her by the API! ;)
SAGAR SAURABH (9 months 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
Adrian Trawka (1 year ago)
Wrong! Make a request to her and in response she might show you her API! ;)
Clever Programmer (1 year ago)
lmaoooo
Yukun Liu (2 years ago)
Hi, I can't sign up at Locu.com anymore.
icketypickety (5 months ago)
search for jsonPlaceholder gives u api for mock data
DSYNC (1 year ago)
That sucks
Abang Jalan2 (1 year ago)
why?
Xan Don (1 year ago)
go daddy shut the locu api signup :(
Nikhil Rao (1 year 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
PURANDHAR BUDDHARAJU (2 years ago)
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)
Darshil D (1 year ago)
thanks!
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!!
Where's Blair? (1 year ago)
"Requests" is a Python library (for Python 2 and 3) that is very easy to work with and very extensible. http://docs.python-requests.org/en/master/
Where's Blair? (1 year ago)
He says he's using 2.7 at the start of the video: https://youtu.be/pxofwuWTs7c?t=121
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?
Dare Sunday (2 months ago)
gotten an answer for this yet?
Sebastián Piedra (2 years ago)
I get an error when I print 'data' for first time. It says: " the JSON object must be str, not 'bytes' ". What am I doing wrong if I was doing exactly what you did?
Differ_Del (2 years ago)
I'm having the same problem, using urllib.request instead of urllib2.
Sebastián Piedra (2 years ago)
+Sebas Piedra And I know that modules change through out each update. I'm working with Python 3.5.1
Never Back Down (2 years ago)
Hello I got a problem with my forum when someone try to make a registration they can't it says: "Submitted form was invalid. Try again." did anybody know how to fix that?
navin narshetty (2 years ago)
To be honest you make great tutorials , but i am stuck with one issue and need your help . i am trying to grab json data of yify website but every time the system says an error- File "C:\Python27\lib\urllib2.py", line 558, in http_error_default raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) HTTPError: HTTP Error 403: Forbidden can you help me on this ?

Would you like to comment?

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