Skip to content

A sample illustrating using the Office 365 APIs from Python/Django

License

Notifications You must be signed in to change notification settings

mahdymo/pythoncontacts

 
 

Repository files navigation

Python Contacts Sample

This sample is an ongoing project with two main goals: to show how to easily use the Office 365 APIs from Python, and to help me learn Python and Django. A couple of things to keep in mind:

  • I am a complete newbie to Python and Django. Other than the "polls" app created as part of the Django tutorial, this is my first ever Python app. Because of that, I may do things in a "less-than-optimal" way from a Python perspective. Feel free to let me know!
  • I chose to target the Contacts API for this sample. However, the same methodology should work for any of the REST APIs.
  • I used the built in Django development server, so I haven't tested this with any production-level servers.
  • I used the SQLite testing database that gets created with the Django project, so anything that gets stored database is in a local file on your development machine.

Required software

Running the sample

It's assumed that you have Python and Django installed before starting. Windows users should add the Python install directory and Scripts subdirectory to their PATH environment variable.

  1. Download or fork the sample project.

  2. Open your command prompt or shell to the directory where manage.py is located.

  3. If you can run BAT files, run setup_project.bat. If not, run the three commands in the file manually. The last command prompts you to create a superuser, which you'll use later to logon.

  4. Install the Requests: HTTP for Humans module from the command line: pip install requests

  5. Register the app in Azure Active Directory. The app should be registered as a web app with a Sign-on URL of "http://127.0.0.1:8000/contacts", and should be given permission to "Read users' contacts".

  6. Edit the .\contacts\clientreg.py file. Copy the client ID for your app obtained during app registration and paste it as the value for the id variable. Copy the key you created during app registration and paste it as the value for the secret variable. Save the file.

  7. Start the development server: python manage.py runserver

  8. You should see output like: Performing system checks...

    System check identified no issues (0 silenced). December 18, 2014 - 12:36:32 Django version 1.7.1, using settings 'pythoncontacts.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CTRL-BREAK.

  9. Use your browser to go to http://127.0.0.1:8000/contacts.

  10. Login with your superuser account.

  11. You should now be prompted to connect your Office 365 account. Click the link to do so and login with an Office 365 account.

  12. You should see a table listing the existing contacts in your Office 365 account. You can click the "New Contact" button to create a new contact, or use the "Edit" or "Delete" buttons on existing contacts.

  13. If you want to see what gets stored in the Django database for the user, go too http://127.0.0.1:8000/admin and click on the Office365 connections link. You can delete the user's record from the admin site too, in case you want to go through the consent process again.

Release history

To get a specific release version, go to https://github.com/jasonjoh/pythoncontacts/releases

  • 1.2: Mail and Calendar functions. The o365service module now has some Mail API and Calendar API functionality. No UI for these functions, but they can be invoked via the new test classes added to test.py. Also added a flag to disable SSL cert validation so that you can capture requests and responses with Fiddler. (Blog Post)
  • 1.1: Contact functions. App now displays a list of contacts and allows the user to create new contacts and edit or delete existing ones. (Blog Post)
  • 1.0: Initial release. App allows user to connect an Office 365 account with a local app account. App does OAuth2 code grant flow and displays the user's access token. (Blog Post)

Copyright

Copyright (c) Microsoft. All rights reserved.


Connect with me on Twitter @JasonJohMSFT

Follow the Exchange Dev Blog

About

A sample illustrating using the Office 365 APIs from Python/Django

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 84.4%
  • HTML 13.7%
  • CSS 1.8%
  • Batchfile 0.1%