Account
- class O365.account.Account(credentials: Tuple[str, str], *, username: str | None = None, protocol: Protocol | None = None, main_resource: str | None = None, **kwargs)[source]
Bases:
object
- __init__(credentials: Tuple[str, str], *, username: str | None = None, protocol: Protocol | None = None, main_resource: str | None = None, **kwargs)[source]
Creates an object which is used to access resources related to the specified credentials.
- Parameters:
credentials – a tuple containing the client_id and client_secret
username – the username to be used by this account
protocol – the protocol to be used in this account
main_resource – the resource to be used by this account (‘me’ or ‘users’, etc.)
kwargs – any extra args to be passed to the Connection instance
- Raises:
ValueError – if an invalid protocol is passed
- address_book(*, resource: str | None = None, address_book: str = 'personal')[source]
Get an instance to the specified address book for the specified account resource
- Parameters:
resource – Custom resource to be used in this address book (Defaults to parent main_resource)
address_book – Choose from ‘Personal’ or ‘Directory’
- Returns:
a representation of the specified address book
- Return type:
AddressBook or GlobalAddressList
- Raises:
RuntimeError – if invalid address_book is specified
- authenticate(*, requested_scopes: list | None = None, redirect_uri: str | None = None, handle_consent: ~typing.Callable = <function consent_input_token>, **kwargs) bool [source]
Performs the console authentication flow resulting in a stored token. It uses the credentials passed on instantiation. Returns True if succeeded otherwise False.
- Parameters:
requested_scopes (list[str]) – list of protocol user scopes to be converted by the protocol or scope helpers or raw scopes
redirect_uri (str) – redirect url configured in registered app
handle_consent – a function to handle the consent process by default just input for the token url
kwargs – other configurations to be passed to the Connection.get_authorization_url and Connection.request_token methods
- get_authenticated_usernames() list[str] [source]
Returns a list of usernames that are authenticated and have a valid access token or a refresh token.
- get_authorization_url(requested_scopes: List[str], redirect_uri: str | None = None, **kwargs) Tuple[str, dict] [source]
Initializes the oauth authorization flow, getting the authorization url that the user must approve.
- Parameters:
requested_scopes (list[str]) – list of scopes to request access for
redirect_uri (str) – redirect url configured in registered app
kwargs – allow to pass unused params in conjunction with Connection
- Returns:
authorization url and the flow dict
- mailbox(resource: str | None = None)[source]
Get an instance to the mailbox for the specified account resource
- Parameters:
resource – Custom resource to be used in this mailbox (Defaults to parent main_resource)
- Returns:
a representation of account mailbox
- Return type:
- new_message(resource: str | None = None)[source]
Creates a new message to be sent or stored
- Parameters:
resource (str) – Custom resource to be used in this message (Defaults to parent main_resource)
- Returns:
New empty message
- Return type:
- outlook_categories(*, resource: str = '')[source]
Returns a Categories object to handle the available Outlook Categories
- request_token(authorization_url: str | None, *, flow: dict = None, requested_scopes: List[str] | None = None, store_token: bool = True, **kwargs) bool [source]
Authenticates for the specified url and gets the oauth token data. Saves the token in the backend if store_token is True. This will replace any other tokens stored for the same username and scopes requested. If the token data is successfully requested, then this method will try to set the username if not previously set.
- Parameters:
authorization_url (str or None) – url given by the authorization flow or None if it’s client credentials
flow (dict) – dict object holding the data used in get_authorization_url
requested_scopes (list[str]) – list of scopes to request access for
store_token (bool) – True to store the token in the token backend, so you don’t have to keep opening the auth link and authenticating every time
kwargs – allow to pass unused params in conjunction with Connection
- Returns:
Success/Failure
- Return type:
bool
- schedule(*, resource: str | None = None)[source]
Get an instance to work with calendar events for the specified account resource
- Parameters:
resource – Custom resource to be used in this schedule object (Defaults to parent main_resource)
- Returns:
a representation of calendar events
- Return type:
Get an instance to read information from Sharepoint sites for the specified account resource
- Parameters:
resource – Custom resource to be used in this sharepoint object (Defaults to parent main_resource)
- Returns:
a representation of Sharepoint Sites
- Return type:
- Raises:
RuntimeError – if protocol doesn’t support the feature
- storage(*, resource: str | None = None)[source]
Get an instance to handle file storage (OneDrive / Sharepoint) for the specified account resource
- Parameters:
resource – Custom resource to be used in this drive object (Defaults to parent main_resource)
- Returns:
a representation of OneDrive File Storage
- Return type:
- Raises:
RuntimeError – if protocol doesn’t support the feature
- property connection
Alias for self.con
- Return type:
type(self.connection_constructor)
- property is_authenticated: bool
Checks whether the library has the authentication data and that is not expired for the current username. This will try to load the token from the backend if not already loaded. Return True if authenticated, False otherwise.
- main_resource: str
The resource in use for the account.
Type: str
- protocol: Protocol
The protocol to use for the account. Defaults ot MSGraphProtocol.
Type: Protocol
- property username: str | None
Returns the username in use for the account