Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Python Tutorial
  • Interview Questions
  • Python Quiz
  • Python Glossary
  • Python Projects
  • Practice Python
  • Data Science With Python
  • Python Web Dev
  • DSA with Python
  • Python OOPs
Open In App
Next Article:
How to Make API Call Using Python
Next article icon

How to Use Mega.nz API With Python?

Last Updated : 22 Nov, 2021
Comments
Improve
Suggest changes
Like Article
Like
Report

In this article, we are going to see how to use mega.nz API with Python. MEGA.NZ is End-to-end encrypted and the encryption keys are owned by us. It means that mega.NZ employees won’t be able to read personal data. Mega.py is a great Python module for interacting with mega.nz API. It provides easy to use functions that can be used for functions like –

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

Installing the Module

Mega. NZ provides an easy-to-use SDK for Python and hence we are going to use it for this tutorial. So First we have to install the SDK.

pip install mega.py

Run this above command to install the SDK. Now move to your favorite IDE.

To Upload File or Folder

Here we are going to upload files in our mega.nz cloud. using upload() function.

Python3

# Enter File/Folder Name
from mega import Mega
  
mega = Mega()
m = mega.login(email, password)
filename = "data.csv"
m.upload(filename)
                      
                       

Output:

Get Information about your Mega Account

Get user details

get_user() method returns a dictionary containing the data about the user. 

Python3

from mega import Mega
  
mega = Mega()
m = mega.login(email, password)
details = m.get_user()
print(details)
                      
                       

Output:

Get account disk quota

get_quota() method return the unused disk space.

Python3

from mega import Mega
  
mega = Mega()
m = mega.login(email, password)
quota = m.get_quota()
print("Total Space: ", quota)
                      
                       

Output:

Download Files From Mega

Here we are going to download files from mega using download_url() methods.

Python3

from mega import Mega
  
  
mega = Mega()
m = mega.login(email, password)
  
# FIND FILE
file = m.find('myfile.doc')
  
# THEN DOWNLOAD USING THE FILE OBJECT
m.download(file)
  
# DOWNLOAD FILE USING MEGA FILE URL
m.download_url(
    'https://mega.co.nz/#!3tUF2KQD!Rg-zOOUIs9L\
    ipsqwH9c_9ZOfRjZ48Xb5k2I1M6QTMa4')
  
# SPECIFY DOWNLOAD LOCATION
m.download(file, '/home/john-smith/Desktop')
                      
                       

Output:

Searching File

Searching file requires the use of the find() function, Here if the file is found it will be a dictionary containing various info about the file, else the file will just be a none type

Python3

from mega import Mega
  
  
mega = Mega()
m = mega.login(email, password)
filename = ""
file = m.find(filename)
print(file)
                      
                       

Output:

Rename a file or a folder

Here we will rename a file using rename() methods.

Python3

from mega import Mega
  
  
mega = Mega()
m = mega.login(email, password)
  
oldFilename = "data.csv"
newFilename = "renamed_data.csv"
file = m.find(oldFilename)
m.rename(file, newFilename)
                      
                       

Output:

How to share a public link of the file so that anyone can download?

get_link() method to return the link of the specific file.

Python3

# Get the File
from mega import Mega
  
mega = Mega()
m = mega.login(email, password)
  
file = m.find("data.csv")
  
# Use it in get_link function
link = m.get_link(file)
  
# It will print the link
print(link)
                      
                       

Output:



Next Article
How to Make API Call Using Python

V

vanshcode
Improve
Article Tags :
  • Python
  • python-modules
Practice Tags :
  • python

Similar Reads

  • How to Use yfinance API with Python
    The yfinance API is a powerful tool for accessing financial data from Yahoo Finance. It allows users to download historical market data, retrieve financial information, and perform various financial analyses. This API is widely used in finance, investment, and trading applications for its ease of us
    3 min read
  • How to Make API Call Using Python
    APIs (Application Programming Interfaces) are an essential part of modern software development, allowing different applications to communicate and share data. Python provides a popular library i.e. requests library that simplifies the process of calling API in Python. In this article, we will see ho
    3 min read
  • Making SOAP API calls using Python
    SOAP stands for Simple Object Access Protocol, as the name suggests nothing but a protocol for exchanging structured data between nodes. It uses XML instead of JSON. In this article, we are going to see how to make SOAP API calls using Python. If you want to test out what exactly the payload and res
    3 min read
  • How to Use Google Cloud Function with Python ?
    Google Cloud Functions provides a way to run small pieces of code in response to cloud events without managing servers. If you're a developer looking to automate tasks, process data or build APIs, Python is a great language for working with Google Cloud Functions. In this article, we will look into
    6 min read
  • How to Download Files from Urls With Python
    Here, we have a task to download files from URLs with Python. In this article, we will see how to download files from URLs using some generally used methods in Python. Download Files from URLs with PythonBelow are the methods to Download files from URLs with Python: Using 'requests' ModuleUsing 'url
    2 min read
  • How to Install a Python Package with a .whl File?
    To install a Python package using a .whl (wheel) file, you'll need to follow a few simple steps. The first method involves using PowerShell along with pip and the cd command to change the directory to where your .whl file is located. The second method uses PowerShell and pip directly, without changi
    4 min read
  • Build APIs with Falcon in Python
    In the sector of web development, building a sturdy and green API is vital. APIs (Application Programming Interfaces) act as a bridge between software program structures, allowing for easy verbal exchange and record change. Python, with its flexibility and flexibility, is a popular choice for growin
    6 min read
  • How to install Python on Windows?
    Python is a high-level programming language that has become increasingly popular due to its simplicity, versatility, and extensive range of applications. The process of How to install Python in Windows, operating system is relatively easy and involves a few uncomplicated steps. This article aims to
    5 min read
  • How to Import Local Modules with Python
    In Python, modules are self-contained files with reusable code units like functions, classes, and variables. Importing local modules allows for organizing the codebase effectively, enhance maintainability, and enhances code reuse. In this article, we will understand how to import local modules with
    3 min read
  • Web crawling with Python
    Web crawling is widely used technique to collect data from other websites. It works by visiting web pages, following links and gathering useful information like text, images, or tables. Python has various libraries and frameworks that support web crawling. In this article we will see about web crawl
    4 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences