This release is a pre-release and may not be stable for production use.
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"]
Metadata
Release files for aiopyo365 0.1.1a0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| aiopyo365-0.1.1a0.tar.gz | 8.0 kB | Without provenance | Details for aiopyo365-0.1.1a0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| aiopyo365-0.1.1a0-py3-none-any.whl | Python 3 | none | any | Details for aiopyo365-0.1.1a0-py3-none-any.whl |
Total release size: 17.5 kB
Release files / aiopyo365-0.1.1a0.tar.gz
| Download URL | aiopyo365-0.1.1a0.tar.gz |
|---|---|
| Size | 8.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8a4626cdb8047db5bee3ff61b1b30eaec0f6b3ed75d9218115b5c0373baa688d
|
|
BLAKE2b-256 checksum How to use checksums |
6790421dcd8df2723dbf6d4b0f716e4bbc246400cd9069bccab0ddf681d75834
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.2.2 CPython/3.8.10 Linux/5.10.16.3-microsoft-standard-WSL2
|
Release files / aiopyo365-0.1.1a0-py3-none-any.whl
| Download URL | aiopyo365-0.1.1a0-py3-none-any.whl |
|---|---|
| Size | 9.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cbe059d82bec1f2fc2c30bdcd91b004b7510aaf3d9c9a4b467046933c1052a4c
|
|
BLAKE2b-256 checksum How to use checksums |
b2f67e784ae82ff652586e791eb2a91fbd01e807f3d8b9840f0edbf2b6d5037a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.2.2 CPython/3.8.10 Linux/5.10.16.3-microsoft-standard-WSL2
|
Security for aiopyo365 0.1.1a0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.