Skip to main content

Mega-v2.py

Python library for the Mega.nz API. Maintained fork of mega.py, updated for Python 3.10+ with httpx.

Currently supporting:

  • login
  • uploading
  • downloading
  • deleting
  • searching
  • sharing
  • renaming
  • moving files

How To Use

Install mega-v2.py package

Run the following command to install from PyPI.

pip install mega-v2.py

Import mega

from mega import Mega

Create an instance of Mega

mega = Mega()

Login to Mega

m = mega.login(email, password)
# login using a temporary anonymous account
m = mega.login()

Get user details

details = m.get_user()

Get account balance (Pro accounts only)

balance = m.get_balance()

Get account disk quota

quota = m.get_quota()

Get account storage space

# specify unit output kilo, mega, gig, else bytes will output
space = m.get_storage_space(kilo=True)

Get account files

files = m.get_files()

Upload a file, and get its public link

file = m.upload('myfile.doc')
m.get_upload_link(file)
# see mega.py for destination and filename options

Export a file or folder

public_exported_web_link = m.export('myfile.doc')
public_exported_web_link = m.export('my_mega_folder/my_sub_folder_to_share')
# e.g. https://mega.nz/#F!WlVl1CbZ!M3wmhwZDENMNUJoBsdzFng

Find a file or folder

folder = m.find('my_mega_folder')
# Excludes results which are in the Trash folder (i.e. deleted)
folder = m.find('my_mega_folder', exclude_deleted=True)

Upload a file to a destination folder

folder = m.find('my_mega_folder')
m.upload('myfile.doc', folder[0])

Download a file from URL or file obj, optionally specify destination folder

file = m.find('myfile.doc')
m.download(file)
m.download_url('https://mega.co.nz/#!utYjgSTQ!OM4U3V5v_W4N5edSo0wolg1D5H0fwSrLD3oLnLuS9pc')
m.download(file, '/home/john-smith/Desktop')
# specify optional download filename (download_url() supports this also)
m.download(file, '/home/john-smith/Desktop', 'myfile.zip')

Import a file from URL, optionally specify destination folder

m.import_public_url('https://mega.co.nz/#!utYjgSTQ!OM4U3V5v_W4N5edSo0wolg1D5H0fwSrLD3oLnLuS9pc')
folder_node = m.find('Documents')[1]
m.import_public_url('https://mega.co.nz/#!utYjgSTQ!OM4U3V5v_W4N5edSo0wolg1D5H0fwSrLD3oLnLuS9pc', dest_node=folder_node)

Create a folder

m.create_folder('new_folder')
m.create_folder('new_folder/sub_folder/subsub_folder')

Returns a dict of folder node name and node_id, e.g.

{
  'new_folder': 'qpFhAYwA',
  'sub_folder': '2pdlmY4Z',
  'subsub_folder': 'GgMFCKLZ'
}

Rename a file or a folder

file = m.find('myfile.doc')
m.rename(file, 'my_file.doc')

Metadata

Release files for mega.py-v2 2.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.py-v2 2.1.0
File Size Uploaded
mega_py_v2-2.1.0.tar.gz 17.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mega.py-v2 2.1.0
File Interpreter ABI Platform
mega_py_v2-2.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 34.9 kB

Release files / mega_py_v2-2.1.0.tar.gz

Download URL mega_py_v2-2.1.0.tar.gz
Size 17.8 kB
Tags Source
SHA-256 checksum
How to use checksums
d59ab78f723051b11a59aa6c8d2ae16d19adad8173168802335457c9f6538f44
BLAKE2b-256 checksum
How to use checksums
ead968c124347793e8eed70e4e5b5f415de5468e51b14f33705a2fa12d92c495
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.15

Release files / mega_py_v2-2.1.0-py3-none-any.whl

Download URL mega_py_v2-2.1.0-py3-none-any.whl
Size 17.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4ff91e906725cda938453371be1a4ebd1f1d3ad310dc0dad8887609a6091d46a
BLAKE2b-256 checksum
How to use checksums
d7dff3c73be119440d2a07e10f297dff4ed7683c6d6a416343b454b90c5ea1de
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.15

Release history Release notifications | RSS feed

This release

2.1.0 This release

2 release files

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