Skip to main content

Python lib for the Mega.co.nz API.

Project description

Async Mega.py (Updated)

PyPI - Version PyPI - Python Version linting - Ruff GitHub License CI

Python library for the Mega.nz API

Supports:

  • login
  • upload
  • download
  • delete
  • search
  • sharing
  • renaming
  • moving files

API Information

Please check src/mega/data_structures.py for details about the objects returned by the API

How To Use

1. Import the client

from mega.client import Mega

2. Create an instance of the client

mega = Mega()

3. Login to Mega

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

Methods

Get user details

details = await mega.get_user()

Get account balance (Pro accounts only)

balance = await mega.get_balance()

Get account disk quota

quota = await mega.get_quota()

Get account storage space

space = await mega.get_storage_space()

Get account files

files = await mega.get_files()

Get files in trash bin

deleted_files = await mega.get_files_in_node(4)  # Options: root(2), inbox(3), trashbin (4)

Get file system

fs = await mega.build_file_system()

Upload a file, and get its public link

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

Export a file or folder

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

Search a file or folder (recursively)

Search returns every file/folder that contains the search query in its path

If you have these files in your account:

├── dir1
│   ├── file1.txt
│   └── file2.md
├── dir2
│   └── subdir
│       └── file3.log
├── trash_bin
│   └── file4.mov
└── file5.txt
result = await mega.search('file1.txt') # Returns a list with 1 element, dir1/file1.txt
result = await mega.search('file') # Returns a list with 5 elements
result = await mega.search('file', exclude_deleted=True) # Returns a list with 4 elements
result = await mega.search('.txt') # Returns a list with 2 elements
result = await mega.search('dir1/file') # Returns a list with 2 elements

Find a file or folder

Like search, but the path must start with the search query and only returns the first element (if found)

result = await mega.find('file3.log') # None
result = await mega.find('dir2/file3.log') # None
result = await mega.find('dir2/subdir/file3') # File() at dir2/subdir/file3.log'
result = await mega.find('dir2/subdir/file3.log') # File() at dir2/subdir/file3.log'

Upload a file to a destination folder

folder = await mega.find('dir2/subdir')
await mega.upload('myfile.doc', dest_node=folder)

Download a file, optionally specify destination folder

file = await mega.find('dir2/subdir/file3.log')
await mega.download(file)
await mega.download(file, dest_path='/home/john-smith/Desktop')
await mega.download(file, dest_path='/home/john-smith/Desktop', dest_filename='my_logs.log')

Download will show a progress bar on the terminal. To disable it, create an instance of the mega client with the progress bar disabled

mega = Mega(use_progress_bar=False)

You can also disable the progress bar on an existing instance

mega.use_progress_bar = False

Download a file from an URL

url = 'https://mega.co.nz/#!utYjgSTQ!OM4U3V5v_W4N5edSo0wolg1D5H0fwSrLD3oLnLuS9pc'
await mega.download_url(url, dest_filename='my_file.zip')

Download a public folder

url = 'https://mega.co.nz/#F!utYjgSTQ!OM4U3V5v_W4N5edSo0wolg1D5H0fwSrLD3oLnLuS9pc'
await mega.download_folder_url(url, dest_path ="downloads/my_music")

Import a file from URL, optionally specify destination folder

url = 'https://mega.co.nz/#!utYjgSTQ!OM4U3V5v_W4N5edSo0wolg1D5H0fwSrLD3oLnLuS9pc'
await mega.import_public_url(url)
folder = await mega.find('dir2')
await mega.import_public_url(url, dest_node=folder)

Create a folder

await mega.create_folder('new_folder')
await mega.create_folder('new_folder/sub_folder/subsub_folder')

Rename a file or a folder

file = await mega.find('dir2/subdir/file3.log')
await mega.rename(file, new_name='dir2/subdir/old_logs.log')

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

async_mega_py-1.11.0.tar.gz (25.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

async_mega_py-1.11.0-py3-none-any.whl (28.0 kB view details)

Uploaded Python 3

File details

Details for the file async_mega_py-1.11.0.tar.gz.

File metadata

  • Download URL: async_mega_py-1.11.0.tar.gz
  • Upload date:
  • Size: 25.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.3

File hashes

Hashes for async_mega_py-1.11.0.tar.gz
Algorithm Hash digest
SHA256 317d8b387f30808ca0fae62595acf64cddce8faf8b602d78085453940fc9142a
MD5 8195744ca958b480e1bb69f592cc0f09
BLAKE2b-256 d1eafddf14b4513491bf7dff3b81d0d06523388b8efdbd89acbb8e4fa0371e13

See more details on using hashes here.

File details

Details for the file async_mega_py-1.11.0-py3-none-any.whl.

File metadata

File hashes

Hashes for async_mega_py-1.11.0-py3-none-any.whl
Algorithm Hash digest
SHA256 74a2c22de65fa6ef1d67b4ac436d6d1d9ac4867fbeb7e7a8da2a682d49568e3e
MD5 7eb97f024c2a58b38d47006c7a96a6c5
BLAKE2b-256 8f1dc2ede100c1fe2f1a57d54e30071318a4539fb5af3d8a30752a56c7e378d3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page