Skip to main content

OneDrive Personal SDK

OneDrive Personal SDK is a Python library for interacting with a personal OneDrive through the Graph API.

Usage

Getting an authentication token

The library is built to support different token providers. To add authentication to the library you need to define a get_access_token method and pass that to the library.

To use msal as a token provider you can create that function like the following:

from msal import PublicClientApplication

app = PublicClientApplication(
    "Client ID",
    authority="https://login.microsoftonline.com/consumers",
)


async def get_access_token(self) -> str:
    result = app.acquire_token_interactive(
        scopes=[
            "Files.ReadWrite.All",
        ]
    )
    return result["access_token"]

Creating a client

To create a client you need to provide a function to retrieve an access token.

from onedrive_personal_sdk import OneDriveClient

client = OneDriveClient(get_access_token)

# can also be created with a custom aiohttp session
client = OneDriveClient(get_access_token, session=session)

Calling the API

The client provides methods to interact with the OneDrive API. The methods are async and return the response from the API. Most methods accept item ids or paths as arguments.

root = await client.get_drive_item("root") # Get the root folder
item = await client.get_drive_item("root:/path/to/item:") # Get an item by path
item = await client.get_drive_item(item.id) # Get an item by id

folder = await client.get_drive_item("root:/path/to/folder:") # Get a folder

# List children of a folder
children = await client.list_children("root:/path/to/folder:")
children = await client.list_children(folder.id)

Uploading files

Smaller files (<250MB) can be uploaded with the upload method. All files need to be provided as AsyncIterators. Such a generator can be created from aiofiles.

import aiofiles
from collections.abc import AsyncIterator

async def file_reader(file_path: str) -> AsyncIterator[bytes]:
    async with aiofiles.open(file_path, "rb") as f:
        while True:
            chunk = await f.read(1024)  # Read in chunks of 1024 bytes
            if not chunk:
                break
            yield chunk
await client.upload_file("root:/TestFolder", "test.txt", file_reader("test.txt"))

Larger files (and small files as well) can be uploaded with a LargeFileUploadClient. The client will handle the upload in chunks.

import os
from onedrive_personal_sdk import LargeFileUploadClient
from onedrive_personal_sdk.models.upload import FileInfo

filename = "testfile.txt"
size = os.path.getsize(filename)

file = FileInfo(
    name=filename,
    size=size,
    folder_path_id="root",
    content_stream=file_reader(filename),
)
file = await LargeFileUploadClient.upload(get_access_token, file)

Adaptive Chunk Size

The LargeFileUploadClient supports adaptive chunk sizing to optimize upload performance based on your connection speed. When enabled, the client dynamically adjusts the chunk size to target approximately 5 seconds per chunk upload, keeping it between 10MB and 60MB by default.

file = await LargeFileUploadClient.upload(
    get_access_token,
    file,
    smart_chunk_size=True,  # Enable adaptive chunk sizing
    upload_chunk_size=320 * 1024,  # Initial chunk size (optional, default: 5.2MB)
    min_chunk_size=32 * 320 * 1024,  # Smallest adapted chunk size (optional, default: 10MB)
    max_chunk_size=60 * 1024 * 1024,  # Largest adapted chunk size (optional, default: 60MB)
    target_chunk_duration=5.0,  # Target seconds per chunk (optional, default: 5.0)
)

All chunk sizes must be multiples of 320kB, and the maximum must not exceed 60MB.

Metadata

Release files for onedrive-personal-sdk 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for onedrive-personal-sdk 0.2.0
File Size Uploaded Provenance
onedrive_personal_sdk-0.2.0.tar.gz 15.6 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for onedrive-personal-sdk 0.2.0
File Interpreter ABI Platform
onedrive_personal_sdk-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 32.6 kB

Release files / onedrive_personal_sdk-0.2.0.tar.gz

Download URL onedrive_personal_sdk-0.2.0.tar.gz
Size 15.6 kB
Tags Source
SHA-256 checksum
How to use checksums
0828c935c435c50012dec91b76b5aa6c26636cfafdfe7e549c5f6c28b59d3b08
BLAKE2b-256 checksum
How to use checksums
5e5409e65dd4dea1f52fb521f75dafbcc18b02a1afc90df138596deaf51ac315
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 18, 2026.

Transparency log

Release files / onedrive_personal_sdk-0.2.0-py3-none-any.whl

Download URL onedrive_personal_sdk-0.2.0-py3-none-any.whl
Size 17.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
781182f0f762209a4196fee6a2359d541f5e50327efa0deaa31af6a10bc44b3f
BLAKE2b-256 checksum
How to use checksums
df769d7d683a0b1c82946d919699ca36d0c7606769b66c087993951940557bdf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 18, 2026.

Transparency log

Security for onedrive-personal-sdk 0.2.0

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.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for onedrive_personal_sdk-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 18, 2026.

Transparency log

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.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page