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.1

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.1
File Size Uploaded Provenance Actions
mega_sdk-0.1.1.tar.gz 15.2 kB Without provenance Details for mega_sdk-0.1.1.tar.gz

Built distribution (wheel)

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

Total release size: 29.4 kB

Release files / mega_sdk-0.1.1.tar.gz

Download URL mega_sdk-0.1.1.tar.gz
Size 15.2 kB
Tags Source
SHA-256 checksum
How to use checksums
c04914919d5175f2ccab0bfa581f2297257db4a283fc884afd967008b2e84fc9
BLAKE2b-256 checksum
How to use checksums
43ba43ae71f770c8e721091515ae1cdde18b3dce05bd1e4fee9cbca5bf7ffaaa
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.1-py3-none-any.whl

Download URL mega_sdk-0.1.1-py3-none-any.whl
Size 14.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0d3d3f86d4fc1525840c8cd58f2e748f07e179a7545f54f379bb9c04327d722d
BLAKE2b-256 checksum
How to use checksums
fe7b145d796fec91c232242b248a31227f643e1d657963e1603be035c4222465
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.1

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.1 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