Skip to main content

mega-sdk

A lightweight, reliable Python client library for interacting with the MEGA.nz API. mega-sdk provides simple abstractions for logging in, uploading/downloading files, managing folders, exporting public links, and handling rate limits with built-in retries.


Features

  • Flexible Login: Support for full user accounts, salt v1/v2 login, and temporary anonymous user sessions.
  • File Management: Upload, download, move, rename, delete, and empty the rubbish bin.
  • Folder Support: Nested folder creation (mkdir / create_folder), path-based folder lookups, and target directory resolution.
  • Sharing & Links: Generate public links for files and folders or import public file URLs directly into your cloud drive.
  • Built-in Backoff: Automatic exponential backoff and retry handling for transient API failures (EAGAIN / rate limits).

Installation

Install mega-sdk directly from PyPI using pip:

pip install mega-sdk

Quick Start

1. User Authentication

from mega_sdk import Mega

# Initialize instance
mega = Mega()

# Login with email and password
mega.login("your_email@example.com", "your_password")

# Get user quota information (in MB)
remaining_quota = mega.get_quota()
print(f"Remaining quota: {remaining_quota:.2f} MB")

2. Anonymous Login

from mega_sdk import Mega

# Login as a temporary anonymous user session
mega = Mega()
mega.login()  # Calling login with no arguments creates an anonymous session

File Operations

Uploading a File

# Basic upload to root folder
uploaded_file = mega.upload("example.pdf")

# Upload with a progress callback
def on_progress(current_bytes, total_bytes):
    percent = (current_bytes / total_bytes) * 100
    print(f"Progress: {percent:.1f}% ({current_bytes}/{total_bytes} bytes)")

mega.upload("large_file.zip", progress_callback=on_progress)

Downloading a File

# Find a file in your cloud drive
file_info = mega.find("example.pdf")

# Download file to a local destination directory
if file_info:
    mega.download(file_info, dest_path="./downloads")

# Download directly via a public MEGA URL
mega.download_url(
    "https://mega.nz/#!file_handle!file_key",
    dest_path="./downloads"
)

Creating Folders

# Create a single directory or nested path in your Cloud Drive
created_folders = mega.create_folder("Documents/Projects/2026")
# Get a shareable link for a file object
file_info = mega.find("example.pdf")
public_link = mega.get_link(file_info)
print("Share link:", public_link)

Exception Handling

mega-sdk exports structured exceptions for API errors:

from mega_sdk import Mega, RequestError, ValidationError

mega = Mega()

try:
    mega.login("user@example.com", "wrong_password")
except RequestError as err:
    print(f"API Error Code {err.code}: {err.message}")
except ValidationError as err:
    print(f"Validation Error: {err}")

Requirements

  • Python: >= 3.8
  • Dependencies: requests, pycryptodome

License

This project is licensed under the MIT License.

Metadata

Release files for mega-sdk 0.1.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 mega-sdk 0.1.0
File Size Uploaded Provenance Actions
mega_sdk-0.1.0.tar.gz 3.0 kB Without provenance Details for mega_sdk-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mega-sdk 0.1.0
File Interpreter ABI Platform Actions
mega_sdk-0.1.0-py3-none-any.whl Python 3 none any Details for mega_sdk-0.1.0-py3-none-any.whl

Total release size: 5.6 kB

Release files / mega_sdk-0.1.0.tar.gz

Download URL mega_sdk-0.1.0.tar.gz
Size 3.0 kB
Tags Source
SHA-256 checksum
How to use checksums
3e8e49a5a84a8264ea74713946eaac060dd69b0b133d93d41a229f78c4dfb4e9
BLAKE2b-256 checksum
How to use checksums
5b0fde8d1ba3c8a87382f6769bbb4ecca4ffc5e3a2331025a597e8181f103a70
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.8

Release files / mega_sdk-0.1.0-py3-none-any.whl

Download URL mega_sdk-0.1.0-py3-none-any.whl
Size 2.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c9ef5eeac4efcef5f2a77da8b35895c607eefa09933e4d3b46d121994d48588b
BLAKE2b-256 checksum
How to use checksums
f95836bbbaeb18d461d97536f3442f753982626883c5116c1e1c01a4170924ef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.8

Security for mega-sdk 0.1.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.

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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No 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