Skip to main content

A Python package to interact with both on-premises and Office 365 Exchange Web Services

Project description

Welcome to py-ews's documentation!

    .______   ____    ____       ___________    __    ____   _______.
    |   _  \  \   \  /   /      |   ____\   \  /  \  /   /  /       |
    |  |_)  |  \   \/   / ______|  |__   \   \/    \/   /  |   (----`
    |   ___/    \_    _/ |______|   __|   \            /    \   \    
    |  |          |  |          |  |____   \    /\    / .----)   |   
    | _|          |__|          |_______|   \__/  \__/  |_______/    

    A Python package to interact with Exchange Web Services

py-ews is a cross platform python package to interact with both Exchange 2010 to 2019 on-premises and Exchange Online (Office 365).

This package will wrap all Exchange Web Service endpoints, but currently is focused on providing eDiscovery endpoints.


py-ews has the following notable features in it's current release:

  • Autodiscover support
  • Delegation support
  • Impersonation support
  • Retrieve all mailboxes that can be searched based on credentials provided
  • Search a list of (or single) mailboxes in your Exchange environment using all supported search attributes
  • Delete email items from mailboxes in your Exchange environment
  • Retrieve mailbox inbox rules for a specific account
  • Find additional hidden inbox rules for a specified account

Currently this package supports the following endpoint's:


OS X & Linux:

pip install py-ews


pip install py-ews

Usage example

The first step in using py-ews is that you need to create a UserConfiguration object. Think of this as all the connection information for Exchange Web Services. An example of creating a UserConfiguration using Office 365 Autodiscover is:

from pyews import UserConfiguration

userconfig = UserConfiguration(

If you would like to use an alternative Autodiscover endpoint (or any alternative endpoint) then please provide one using the endpoint named parameter:

from pyews import UserConfiguration

userconfig = UserConfiguration(

For more information about creating a UserConfiguration object, please see the full documentation.

Now that you have a UserConfiguration object, we can now use any of the available service endpoints. This example will demonstrate how you can identify which mailboxes you have access to by using the GetSearchableMailboxes EWS endpoint.

Once you have identified a list of mailbox reference ids, then you can begin searching all of those mailboxes by using the SearchMailboxes EWS endpoint.

The returned results will then be deleted (moved to Deleted Items folder) from Exchange using the DeleteItem EWS endpoint.

from pyews import UserConfiguration
from pyews import GetSearchableMailboxes
from pyews import SearchMailboxes
from pyews import DeleteItem

userconfig = UserConfiguration(

# get searchable mailboxes based on your accounts permissions
referenceid_list = []
for mailbox in GetSearchableMailboxes(userconfig).run():

# let's search all the referenceid_list items
messages_found = []
for search in SearchMailboxes(userconfig).run('subject:account', referenceid_list):
      # we can print the results first if we want

# if we wanted to now delete a specific message then we would call the DeleteItem 
# class like this but we can also pass in the entire messages_found list
deleted_message_response = DeleteItem(userconfig).run(messages_found[2])


The following is an example of the output returned when calling the above code:

Josh Rickard
Upgrade Your Account!
Josh Rickard
Josh Rickard 
New or modified user account information
Microsoft Online Services Team
[{'MessageText': 'Succesfull'}]

For more examples and usage, please refer to the individual class documentation

Development setup

I have provided a Dockerfile with all the dependencies and it is currently calling If you want to test new features, I recommend that you use this Dockerfile. You can call the following to build a new container, but keep the dependencies unless they have changed in your requirements.txt or any other changes to the Dockerfile.

docker build --force-rm -t pyews .

To run the container, use the following:

docker run pyews

I am new to Unit Testing, but I am working on that as time permits. If you would like to help, I wouldn't be sad about it. :)

Release History

  • 1.0.0
    • Initial release of py-ews and it is still considered a work in progress
  • 2.0.0
    • Revamped logic and overhauled all endpoints and classes


Josh Rickard – @MSAdministrator

Distributed under the MIT license. See LICENSE for more information.


  1. Fork it (
  2. Create your feature branch (git checkout -b feature/fooBar)
  3. Commit your changes (git commit -am 'Add some fooBar')
  4. Push to the branch (git push origin feature/fooBar)
  5. Create a new Pull Request
.. toctree::
   :maxdepth: 2
   :caption: Contents:


Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for py-ews, version 2.0.2
Filename, size File type Python version Upload date Hashes
Filename, size py_ews-2.0.2-py2-none-any.whl (29.2 kB) File type Wheel Python version py2 Upload date Hashes View
Filename, size py_ews-2.0.2-py3-none-any.whl (29.2 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size py-ews-2.0.2.tar.gz (17.3 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page