A Python interface for interacting with Microsoft's OneDrive.
Project description
OFB Python SDK
The ofb-python-sdk
provides a Python interface for interacting with Microsoft's OneDrive. It simplifies the process of authenticating, uploading, downloading, and managing files on OneDrive through a simple and intuitive API. This SDK is particularly useful for developers who need to integrate OneDrive functionalities within their Python applications efficiently.
Features
- Authentication with OAuth2
- Upload files to OneDrive (supports both small and large files)
- Download files from OneDrive
- Create and manage folders
- Delete files and folders
- Handle file conflicts with customizable behavior
- Rich progress bar integration for file uploads
Installation
Install ofb-python-sdk
using pip:
pip install sy-ofb-python-sdk
Usage
To start using the SDK, you'll first need to import the Client
class from the package.
from ofb_python_sdk import Client
Setup
Initialize the client with your application credentials:
client = Client(
client_id="your_client_id",
client_secret="your_client_secret",
refresh_token="your_refresh_token",
redirect_uri="your_redirect_uri",
)
Upload a File
file_path = "/path/to/your/file"
file_data = open(file_path, "rb").read()
remote_path = "/path/to/onedrive/destination/file.txt"
try:
response = client.upload_file(file_data, remote_path)
print("Upload successful:", response.status_code)
except Exception as e:
print("Upload failed:", e)
Download a File
remote_path = "/path/to/onedrive/file.txt"
try:
file_data = client.download_file(remote_path)
with open("downloaded_file.txt", "wb") as file:
file.write(file_data)
print("Download successful")
except Exception as e:
print("Download failed:", e)
Create a Folder
folder_path = "/new/folder"
try:
response = client.create_folder(folder_path)
print("Folder creation successful:", response.status_code)
except Exception as e:
print("Folder creation failed:", e)
Delete a File
remote_path = "/path/to/delete/file.txt"
try:
response = client.delete_file(remote_path)
print("Deletion successful:", response.status_code)
except Exception as e:
print("Deletion failed:", e)
Search a File
keyword = "sometext"
try:
result: list = client.search_files(keyword)
print("Search successful:", result)
except Exception as e:
print("Search failed:", e)
Contributing
Contributions are welcome! Please read the CONTRIBUTING.md for guidelines on how to contribute to this project.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
If you need assistance or encounter any bugs, please open an issue on the project's GitHub issues page.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file sy_ofb_python_sdk-0.1.1.tar.gz
.
File metadata
- Download URL: sy_ofb_python_sdk-0.1.1.tar.gz
- Upload date:
- Size: 9.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fdb6909ec29f169f6093d40f3212fe8dfd3a69d8861f604caef63a925001fe54 |
|
MD5 | 310288a4c93c111b91791d938d0d6362 |
|
BLAKE2b-256 | cfedc13d160acf622dc0e6f4ec00e03b627265a1b56b62fe379a2f52149e3b5a |
File details
Details for the file sy_ofb_python_sdk-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: sy_ofb_python_sdk-0.1.1-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c2f23abf93135f025c3104ce2b04c45dc5eb285e4f48df7282c961bea681692 |
|
MD5 | fbccabf09229e1e94767f797523dc906 |
|
BLAKE2b-256 | 2186f6b36bcf3d428c4cce9098d2c949776e1676b8853847ac011fddd77d32ca |