Python Forum

Full Version: How to Use Temboo with Python
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.

  1. GET SET UP

  2. Log in to Temboo. If you don't already have an account, you can register for free here.

  3. Download the Temboo Python SDK and extract the ZIP file to the directory where you'd like to build this Python sample project.

  4. Create 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).

    TEST ON OUR WEBSITE

  5. Go to the Google > Geocoding > GeocodeByAddress Choreo in our Library. Select Python from the drop down menu at the top of the page.

    [Image: processing-screen-geocoding-input.png]


  6. Enter any address or ZIP code in the Address input field e.g., 104 Franklin Street, New York City.

  7. Click 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.

    [Image: processing-screen-geocoding-output.png]

    AUTO-GENERATE THE CODE

    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.

  8. Scroll down to find the Code section of the Choreo page.

  9. Copy 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())
    TRY IT OUT

  10. Now 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.

WHAT NEXT?
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.

COMMIT CODE TO GITHUB

Commit Temboo-generated code directly to GitHub and share with the world. Learn more.