Skip to main content

No project description provided

Project description

aiopyo365

Async wrapper for Python >= 3.8 around Microsoft v1.0 graph API.

Installation

pip install aiopyo365

Requirements

python 3.8 or greater

Application registration

Microsoft Graph APi requires to be authentificated. You will need to have a registred application in Azure that will provide you:

  • client id
  • client secret

You will also need to have the required permissions to be able to interact with the desired ressources.

Installation

#TODO

Authentification

To authentificate you can use the GraphAuthProvider class in the providers.auth module.

here is how to use this class. it assumes that you have set the folowing environnement variables :

  • CLIENT_ID
  • CLIENT_SECRET
  • TENANT_ID

The class provide a method to fetch the token in the form of a dict.

import asyncio
from aiopyo365.providers.auth import GraphAuthProvider

async def fetch_auth_header():
    auth_provider =  GraphAuthProvider(
            client_id=os.environ["CLIENT_ID"],
            client_secret=os.environ["CLIENT_SECRET"],
            tenant_id=os.environ["TENANT_ID"],
        )
    return await auth_provider.auth()


if __name__ == '__main__':
    auth_header = asyncio.run(fetch_auth_header())
    print(auth_header)


# output : {"authorization": "<token type> <token>"}

Ressources

The library tries to resemble the organization of the graph API documentation.

for instance in the Graph documentation you will find the DriveItems under the Files section.
In aiopyo365:

from aiopyo365.ressources.files import DriveItems

If you want to work directly with ressources class you will need to instanciate a aiohttp session with auth header and instanciate the client class.

import asyncio
import aiohttp
from aiopyo365.ressources.files import DriveItems

async def upload_smallfile(content,file_name):
    auth_provider =  GraphAuthProvider(
            client_id=os.environ["CLIENT_ID"],
            client_secret=os.environ["CLIENT_SECRET"],
            tenant_id=os.environ["TENANT_ID"],
        )
    auth_header = await auth_provider.auth()
    session = await aiohttp.ClientSession(headers=auth_header)
    drive_items_client = DriveItems(base_url="url", session=session)
    await drive_items_client.upload_small_file(content, file_name)
    

You can also use factories to work with variant of ressources here we work with a driveItems dedicated to SharePoint (site).

import asyncio
import aiohttp
import os
from aiopyo365.providers.auth import GraphAuthProvider
from aiopyo365.factories.drive_items import DriveItemsSitesFactory

async def upload_smallfile(content,file_name):
    auth_provider =  GraphAuthProvider(
            client_id=os.environ["CLIENT_ID"],
            client_secret=os.environ["CLIENT_SECRET"],
            tenant_id=os.environ["TENANT_ID"],
        )
    auth_header = await auth_provider.auth()
    session = await aiohttp.ClientSession(headers=auth_header)
    drive_items_client = DriveItemsSitesFactory(site_id="site_id").create(session=session)
    await drive_items_client.upload_small_file(content, file_name)
    

Services

aiopyo365 provide also service class that encapsulate many ressource to match business logic. It hides dealing with instanciate class client and so on. Let's reuse the upload of a file example from above and use the SharePointService

import os
from aiopyo365.providers.auth import GraphAuthProvider
from aiopyo365.services.sharepoint import SharePointService

async def upload_smallfile(content,file_name):
    auth_provider =  GraphAuthProvider(
            client_id=os.environ["CLIENT_ID"],
            client_secret=os.environ["CLIENT_SECRET"],
            tenant_id=os.environ["TENANT_ID"],
        )
    async with SharePointService(auth_provider,"SHAREPOINT_HOSTNAME","SHAREPOINT_SITE") as sharepoint:
        resp = await sharepoint.upload(
            small_file_path, "small_file", conflict_behavior="replace"
        )
        assert resp["createdDateTime"]
    

Project details


Download files

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

Source Distribution

aiopyo365-0.1.1a0.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

aiopyo365-0.1.1a0-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file aiopyo365-0.1.1a0.tar.gz.

File metadata

  • Download URL: aiopyo365-0.1.1a0.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.8.10 Linux/5.10.16.3-microsoft-standard-WSL2

File hashes

Hashes for aiopyo365-0.1.1a0.tar.gz
Algorithm Hash digest
SHA256 8a4626cdb8047db5bee3ff61b1b30eaec0f6b3ed75d9218115b5c0373baa688d
MD5 e8a1475814f45b6cbb925b294c3dcfdf
BLAKE2b-256 6790421dcd8df2723dbf6d4b0f716e4bbc246400cd9069bccab0ddf681d75834

See more details on using hashes here.

File details

Details for the file aiopyo365-0.1.1a0-py3-none-any.whl.

File metadata

  • Download URL: aiopyo365-0.1.1a0-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.8.10 Linux/5.10.16.3-microsoft-standard-WSL2

File hashes

Hashes for aiopyo365-0.1.1a0-py3-none-any.whl
Algorithm Hash digest
SHA256 cbe059d82bec1f2fc2c30bdcd91b004b7510aaf3d9c9a4b467046933c1052a4c
MD5 7101750325c8814afe41988d50620ef9
BLAKE2b-256 b2f67e784ae82ff652586e791eb2a91fbd01e807f3d8b9840f0edbf2b6d5037a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page