Temboo makes it easy to build Python applications that connect to over 100 web-based resources and services (e.g. Facebook, Dropbox, US Census data) by standardizing how you interact with their Application Programming Interfaces (APIs). Don't worry if you're not familiar with APIs – with Temboo you don't have to worry about the details.
Here we'll show you how to use the Temboo Python SDK to write a simple Python script that uses Google's Geocoding API to retrieve the latitude and longitude for a specific address e.g., 104 Franklin St, New York City. What makes Temboo uniquely powerful and useful is that, once you know how to use one API, you know how to work with any API in our Library.
Before we get started, make sure that you've got Python 2.6 or later on your system.
1Log in to Temboo. If you don't already have an account, you can register for free here.
2Download the Temboo Python SDK and extract the ZIP file to the directory where you'd like to build this Python sample project.
3Create a new .py
file in the same location as the unzipped temboo folder. In this example, we'll call the file HelloTemboo.py
(though you can call it whatever you like).
4Go to the Google > Geocoding > GeocodeByAddress Choreo in our Library. Select Python from the drop down menu at the top of the page.
5Enter any address or ZIP code in the Address input field e.g., 104 Franklin Street, New York City.
6Click Generate Code to test the Choreo from our website. After a moment you'll see the data that Google sends back shown in the Output section.
When you run any Choreo from our website, we automatically generate code that can be used to make the same API call in many languages, including Python. Here we'll show you how to use these snippets in your code.
7Scroll down to find the Code section of the Choreo page.
8Copy the code snippet and paste it into your HelloTemboo.py
file. At this point, your code should look something like the script below.
from temboo.Library.Google.Geocoding import GeocodeByAddress from temboo.core.session import TembooSession # Create a session with your Temboo account details session = TembooSession('ACCOUNT_NAME', 'APP_NAME', 'APP_KEY') # Instantiate the Choreo geocodeByAddressChoreo = GeocodeByAddress(session) # Get an InputSet object for the Choreo geocodeByAddressInputs = geocodeByAddressChoreo.new_input_set() # Set the Choreo inputs geocodeByAddressInputs.set_Address("104 Franklin St., New York NY 10013") # Execute the Choreo geocodeByAddressResults = geocodeByAddressChoreo.execute_with_results(geocodeByAddressInputs) # Print the Choreo outputs print("Longitude: " + geocodeByAddressResults.get_Longitude()) print("Latitude: " + geocodeByAddressResults.get_Latitude()) print("Response: " + geocodeByAddressResults.get_Response())
9Now you're ready to run the script and see the output. Here's the command you need to run if you're executing this from the command line. Otherwise just run it from your IDE.
python HelloTemboo.py
Congrats! You just ran your first Choreo! You should see the coordinates for the address you specified printed to the console.
Now you're ready to run any of our 2000+ Choreos in Python. You're just a few steps away from making something extraordinary.
Once you've got your code up and running, you're ready to move on and do more. From monitoring your running applications, to moving your generated Temboo code to your preferred development environment and sharing it with colleagues, collaborators and friends - we've got you covered.
We're always happy to help. Just email us at support@temboo.com, and we'll answer your questions.