Python: OneDriveCLI
I have a couple of laptops. The main one sits on a stand next to a decent sized monitor. The other is older, much smaller but useful for sitting up in bed when it’s cold or I’m a touch under the weather. Both machines dual boot Windows and Pop OS, but I tend to spend most of my time in Pop OS. I also have a subscription to Microsoft 365, including OneDrive which is not simple to access when in Linux.
To resolve this, on my main laptop I use software called InSync which automatically replicates OneDrive files and folders to my local storage. It’s great and stable, but it’s commercial software and it’s one licence per machine. I could buy another licence for my older laptop but it’s rare that I actually need loads of OneDrive data, it’s usually just one or two items. Instead, I thought I’d try and write a small utility that would let me access to OneDrive items on Linux without bloat and expense.
The result is OneDrive CLI, a Python application that lets you navigate around OneDrive using familiar commands such as cd
, ls
, mkdir
. You can also use it to download (get
) files to local storage and upload (put
)files and folders to OneDrive.
The last two posts talk about MSAL and Microsoft Graph token access. These were a result of writing this tool. I found that MSAL was great, but contained a lot of stuff I wasn’t using as I only needed access to consumer OneDrives and it bloated the final distribution somewhat. Reading the MSAL source code and Microsoft documentation to figure out a more direct way of getting OneDrive authorisation and access tokens from the API meant a leaner source footprint. Oh, and it was fun.
Full README and instructions can be found in the Repo here. It hasn’t been uploaded to PyPi, yet, but probably will be in due course. The tool can be fully installed from the source, though.