Mega.py
=======
[![Build
Status](https://travis-ci.org/odwyersoftware/mega.py.png?branch=master)](https://travis-ci.org/odwyersoftware/mega.py)
[![Downloads](https://pypip.in/d/mega.py/badge.png)](https://crate.io/packages/mega.py/) [![PyPI version](https://badge.fury.io/py/mega.py.svg)](https://pypi.org/project/mega.py/)
Python library for the [Mega.co.nz](https://mega.nz/aff=Zo6IxNaHw14)
API, currently supporting:
- login
- uploading
- downloading
- deleting
- searching
- sharing
- renaming
- moving files
This is a work in progress, further functionality coming shortly.
For more detailed information see API\_INFO.md
How To Use
----------
### Create a Mega account
First, [create an account with Mega](https://mega.nz/aff=Zo6IxNaHw14) .
### Install mega.py package
Run the following command, or run setup from the latest github source.
```python
pip install mega.py
```
### Import mega.py
```python
from mega import Mega
```
### Create an instance of Mega.py
```python
mega = Mega()
```
### Login to Mega
```python
m = mega.login(email, password)
# login using a temporary anonymous account
m = mega.login()
```
### Get user details
```python
details = m.get_user()
```
### Get account balance (Pro accounts only)
```python
balance = m.get_balance()
```
### Get account disk quota
```python
quota = m.get_quota()
```
### Get account storage space
```python
# specify unit output kilo, mega, gig, else bytes will output
space = m.get_storage_space(kilo=True)
```
### Get account files
```python
files = m.get_files()
```
### Upload a file, and get its public link
```python
file = m.upload('myfile.doc')
m.get_upload_link(file)
# see mega.py for destination and filename options
```
### Export a file or folder
```python
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
```python
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
```python
folder = m.find('my_mega_folder')
m.upload('myfile.doc', folder[0])
```
### Download a file from URL or file obj, optionally specify destination folder
```python
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
```python
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
```python
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.
```python
{
'new_folder': 'qpFhAYwA',
'sub_folder': '2pdlmY4Z',
'subsub_folder': 'GgMFCKLZ'
}
```
### Rename a file or a folder
```python
file = m.find('myfile.doc')
m.rename(file, 'my_file.doc')
```
## Contact Support
For paid priority support contact [mega@odwyer.software](mailto:mega@odwyer.software).
**[UK Python Development Agency](https://odwyer.software/)**
Release History
===============
1.0.8 (2020-06-25)
------------------
- Fixes find method returning the wrong file when more than one file
exists with that name.
- Handle new shared file URLS.
1.0.7 (2020-03-25)
------------------
- Fix login by calculating public RSA exponent instead of hardcoding.
1.0.6 (2020-02-03)
------------------
- Fixes RSA public exponent issue.
- Switches dependency pycrypto to pycryptodome.
1.0.5 (2019-11-18)
------------------
- Increase the wait time in between failed API request retries.
1.0.4 (2019-11-18)
------------------
- Increase the wait time in between failed API request retries.
1.0.3 (2019-11-12)
------------------
- Fixes broken `download` method.
- Changes `download` and `download_url` methods to return the path to
the downloaded file, previously returned `None`.
- Added LICENSE.
1.0.2 (2019-11-07)
------------------
- Reverts, "Replace pycrypto dependency with pycryptodome" as breaks
login process.
1.0.1 (2019-11-06)
------------------
- When a request fails due to EAGAIN response, retry with exp backoff
up to 20 seconds.
- Adds logging, removes print statements.
- Replace pycrypto dependency with pycryptodome.
- Removes Python 2 specific code.
1.0.0 (2019-10-31)
------------------
- Removes broken method `get_contacts()`.
- Adds support for login with a v2 Mega user account.
- Adds `export()` method to share a file or folder, returning public
share URL with key.
- Adds code, message attrs to RequestError exception, makes message in
raised exceptions include more details.
- Alters `create_folder()` to accept a path including multiple sub
directories, adds support to create them all (similar to 'mkdir -p'
on unix systems).
- Adds `exclude_deleted=True` optional arg to `find()` method, to
exclude deleted nodes from results.
0.9.20 (2019-10-17)
-------------------
- Python 3 bugfix to `upload` method.
0.9.19 (2019-10-16)
-------------------
- Python 3 support and bugfixes.
- Update packaging code.
- Added changelog.
0.9.18 (2013-07-04)
-------------------
- Unknown
Raw data
{
"_id": null,
"home_page": "https://github.com/odwyersoftware/mega.py",
"name": "mega.py",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "",
"author": "O'Dwyer Software",
"author_email": "hello@odwyer.software",
"download_url": "https://files.pythonhosted.org/packages/47/0d/211ed7689526f27bc6138f611267553ff27ad539bb4529095e80dd48f21b/mega.py-1.0.8.tar.gz",
"platform": "",
"description": "Mega.py\n=======\n\n[![Build\nStatus](https://travis-ci.org/odwyersoftware/mega.py.png?branch=master)](https://travis-ci.org/odwyersoftware/mega.py)\n[![Downloads](https://pypip.in/d/mega.py/badge.png)](https://crate.io/packages/mega.py/) [![PyPI version](https://badge.fury.io/py/mega.py.svg)](https://pypi.org/project/mega.py/)\n\nPython library for the [Mega.co.nz](https://mega.nz/aff=Zo6IxNaHw14)\nAPI, currently supporting:\n\n- login\n- uploading\n- downloading\n- deleting\n- searching\n- sharing\n- renaming\n- moving files\n\nThis is a work in progress, further functionality coming shortly.\n\nFor more detailed information see API\\_INFO.md\n\nHow To Use\n----------\n\n### Create a Mega account\n\nFirst, [create an account with Mega](https://mega.nz/aff=Zo6IxNaHw14) .\n\n### Install mega.py package\n\nRun the following command, or run setup from the latest github source.\n\n```python\npip install mega.py\n```\n\n### Import mega.py\n\n```python\nfrom mega import Mega\n```\n\n### Create an instance of Mega.py\n\n```python\nmega = Mega()\n```\n\n### Login to Mega\n\n```python\nm = mega.login(email, password)\n# login using a temporary anonymous account\nm = mega.login()\n```\n\n### Get user details\n\n```python\ndetails = m.get_user()\n```\n\n### Get account balance (Pro accounts only)\n\n```python\nbalance = m.get_balance()\n```\n\n### Get account disk quota\n\n```python\nquota = m.get_quota()\n```\n\n### Get account storage space\n\n```python\n# specify unit output kilo, mega, gig, else bytes will output\nspace = m.get_storage_space(kilo=True)\n```\n\n### Get account files\n\n```python\nfiles = m.get_files()\n```\n\n### Upload a file, and get its public link\n\n```python\nfile = m.upload('myfile.doc')\nm.get_upload_link(file)\n# see mega.py for destination and filename options\n```\n\n### Export a file or folder\n\n```python\npublic_exported_web_link = m.export('myfile.doc')\npublic_exported_web_link = m.export('my_mega_folder/my_sub_folder_to_share')\n# e.g. https://mega.nz/#F!WlVl1CbZ!M3wmhwZDENMNUJoBsdzFng\n```\n\n### Find a file or folder\n\n```python\nfolder = m.find('my_mega_folder')\n# Excludes results which are in the Trash folder (i.e. deleted)\nfolder = m.find('my_mega_folder', exclude_deleted=True)\n```\n\n### Upload a file to a destination folder\n\n```python\nfolder = m.find('my_mega_folder')\nm.upload('myfile.doc', folder[0])\n```\n\n### Download a file from URL or file obj, optionally specify destination folder\n\n```python\nfile = m.find('myfile.doc')\nm.download(file)\nm.download_url('https://mega.co.nz/#!utYjgSTQ!OM4U3V5v_W4N5edSo0wolg1D5H0fwSrLD3oLnLuS9pc')\nm.download(file, '/home/john-smith/Desktop')\n# specify optional download filename (download_url() supports this also)\nm.download(file, '/home/john-smith/Desktop', 'myfile.zip')\n```\n\n### Import a file from URL, optionally specify destination folder\n\n```python\nm.import_public_url('https://mega.co.nz/#!utYjgSTQ!OM4U3V5v_W4N5edSo0wolg1D5H0fwSrLD3oLnLuS9pc')\nfolder_node = m.find('Documents')[1]\nm.import_public_url('https://mega.co.nz/#!utYjgSTQ!OM4U3V5v_W4N5edSo0wolg1D5H0fwSrLD3oLnLuS9pc', dest_node=folder_node)\n```\n\n### Create a folder\n\n```python\nm.create_folder('new_folder')\nm.create_folder('new_folder/sub_folder/subsub_folder')\n```\n\nReturns a dict of folder node name and node\\_id, e.g.\n\n```python\n{\n 'new_folder': 'qpFhAYwA',\n 'sub_folder': '2pdlmY4Z',\n 'subsub_folder': 'GgMFCKLZ'\n}\n```\n\n### Rename a file or a folder\n\n```python\nfile = m.find('myfile.doc')\nm.rename(file, 'my_file.doc')\n```\n\n## Contact Support\n\nFor paid priority support contact [mega@odwyer.software](mailto:mega@odwyer.software).\n\n**[UK Python Development Agency](https://odwyer.software/)**\n\n\nRelease History\n===============\n\n1.0.8 (2020-06-25)\n------------------\n\n- Fixes find method returning the wrong file when more than one file\n exists with that name.\n- Handle new shared file URLS.\n\n1.0.7 (2020-03-25)\n------------------\n\n- Fix login by calculating public RSA exponent instead of hardcoding.\n\n1.0.6 (2020-02-03)\n------------------\n\n- Fixes RSA public exponent issue.\n- Switches dependency pycrypto to pycryptodome.\n\n1.0.5 (2019-11-18)\n------------------\n\n- Increase the wait time in between failed API request retries.\n\n1.0.4 (2019-11-18)\n------------------\n\n- Increase the wait time in between failed API request retries.\n\n1.0.3 (2019-11-12)\n------------------\n\n- Fixes broken `download` method.\n- Changes `download` and `download_url` methods to return the path to\n the downloaded file, previously returned `None`.\n- Added LICENSE.\n\n1.0.2 (2019-11-07)\n------------------\n\n- Reverts, \"Replace pycrypto dependency with pycryptodome\" as breaks\n login process.\n\n1.0.1 (2019-11-06)\n------------------\n\n- When a request fails due to EAGAIN response, retry with exp backoff\n up to 20 seconds.\n- Adds logging, removes print statements.\n- Replace pycrypto dependency with pycryptodome.\n- Removes Python 2 specific code.\n\n1.0.0 (2019-10-31)\n------------------\n\n- Removes broken method `get_contacts()`.\n- Adds support for login with a v2 Mega user account.\n- Adds `export()` method to share a file or folder, returning public\n share URL with key.\n- Adds code, message attrs to RequestError exception, makes message in\n raised exceptions include more details.\n- Alters `create_folder()` to accept a path including multiple sub\n directories, adds support to create them all (similar to 'mkdir -p'\n on unix systems).\n- Adds `exclude_deleted=True` optional arg to `find()` method, to\n exclude deleted nodes from results.\n\n0.9.20 (2019-10-17)\n-------------------\n\n- Python 3 bugfix to `upload` method.\n\n0.9.19 (2019-10-16)\n-------------------\n\n- Python 3 support and bugfixes.\n- Update packaging code.\n- Added changelog.\n\n0.9.18 (2013-07-04)\n-------------------\n\n- Unknown\n\n\n\n",
"bugtrack_url": null,
"license": "Creative Commons Attribution-Noncommercial-Share Alike license",
"summary": "Python lib for the Mega.co.nz API",
"version": "1.0.8",
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"md5": "c40230d93f25cd55dabb9ffa20d054d4",
"sha256": "863b2dd59f8e639402fef3c67778fd63895fc1b678127e7006df1544f04e737c"
},
"downloads": -1,
"filename": "mega.py-1.0.8-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "c40230d93f25cd55dabb9ffa20d054d4",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": null,
"size": 19529,
"upload_time": "2020-06-25T20:44:26",
"upload_time_iso_8601": "2020-06-25T20:44:26.485583Z",
"url": "https://files.pythonhosted.org/packages/a3/51/44a1085a091c27ade09e122d5abdafb4b6400265081879a7c4e32973a175/mega.py-1.0.8-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"md5": "323b47bc5bf9a843864d54ddad6f70c8",
"sha256": "0632664abda8b7e4d0bbd68460da4b331d3d7d63db9afe7d3ce6fcb4f137c1a9"
},
"downloads": -1,
"filename": "mega.py-1.0.8.tar.gz",
"has_sig": false,
"md5_digest": "323b47bc5bf9a843864d54ddad6f70c8",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 18608,
"upload_time": "2020-06-25T20:44:27",
"upload_time_iso_8601": "2020-06-25T20:44:27.728882Z",
"url": "https://files.pythonhosted.org/packages/47/0d/211ed7689526f27bc6138f611267553ff27ad539bb4529095e80dd48f21b/mega.py-1.0.8.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2020-06-25 20:44:27",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "odwyersoftware",
"github_project": "mega.py",
"travis_ci": true,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "requests",
"specs": [
[
">=",
"0.10"
]
]
},
{
"name": "pycryptodome",
"specs": [
[
">=",
"3.9.6"
],
[
"<",
"4.0.0"
]
]
},
{
"name": "pathlib",
"specs": [
[
"==",
"1.0.1"
]
]
},
{
"name": "tenacity",
"specs": [
[
"<",
"6.0.0"
],
[
">=",
"5.1.5"
]
]
}
],
"tox": true,
"lcname": "mega.py"
}