README.rst 4.49 KB
Newer Older
richardARPANET's avatar
richardARPANET committed
1
**NOTICE**: If you're reading this on GitHub.com please be aware this is
richardARPANET's avatar
richardARPANET committed
2
a mirror of the primary remote located at https://code.richard.do/richardARPANET/mega.py_. Please direct issues and
richardARPANET's avatar
richardARPANET committed
3 4 5 6 7 8 9 10 11 12 13
pull requests there.

--------------

.. _megapy:

Mega.py
=======

|Build Status| |Downloads|

richardARPANET's avatar
richardARPANET committed
14
Python library for the `Mega.co.nz <https://mega.nz/aff=Zo6IxNaHw14>`_ API, currently supporting:
richardARPANET's avatar
richardARPANET committed
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

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

richardARPANET's avatar
richardARPANET committed
32 33 34 35 36 37 38 39
.. _create-mega-account:

Create a Mega account
~~~~~~~~~~~~~~~~~~~~~~~

First, `create an account with Mega <https://mega.nz/aff=Zo6IxNaHw14>`_
.

richardARPANET's avatar
richardARPANET committed
40 41 42 43 44 45 46
.. _install-megapy-package:

Install mega.py package
~~~~~~~~~~~~~~~~~~~~~~~

.. code:: python

richardARPANET's avatar
richardARPANET committed
47
   Run the following command, or run setup from the latest github source
richardARPANET's avatar
richardARPANET committed
48
   pip install mega.py
richardARPANET's avatar
richardARPANET committed
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121

.. _import-megapy:

Import mega.py
~~~~~~~~~~~~~~

.. code:: python

   from mega import Mega

.. _create-an-instance-of-megapy:

Create an instance of Mega.py
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. code:: python

   mega = Mega()

Login to Mega
~~~~~~~~~~~~~

.. code:: python

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

Get user details
~~~~~~~~~~~~~~~~

.. code:: python

   details = m.get_user()

Get account balance (Pro accounts only)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. code:: python

   balance = m.get_balance()

Get account disk quota
~~~~~~~~~~~~~~~~~~~~~~

.. code:: python

   quota = m.get_quota()

Get account storage space
~~~~~~~~~~~~~~~~~~~~~~~~~

.. code:: python

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

Get account files
~~~~~~~~~~~~~~~~~

.. code:: python

   files = m.get_files()

Upload a file, and get its public link
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. code:: python

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

richardARPANET's avatar
docs  
richardARPANET committed
122 123 124 125 126 127 128 129 130
Export a file or folder
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. code:: 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

Richard's avatar
Richard committed
131
Find a file or folder
132 133 134 135 136 137 138 139
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. code:: 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)

richardARPANET's avatar
richardARPANET committed
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
Upload a file to a destination folder
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. code:: 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
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. code:: 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
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. code:: 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
~~~~~~~~~~~~~~~

.. code:: python

   m.create_folder('new_folder')
175 176 177 178 179 180 181 182 183 184 185
   m.create_folder('new_folder/sub_folder/subsub_folder')

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

.. code:: python

    {
      'new_folder': 'qpFhAYwA',
      'sub_folder': '2pdlmY4Z',
      'subsub_folder': 'GgMFCKLZ'
    }
richardARPANET's avatar
richardARPANET committed
186 187 188 189 190 191 192 193 194

Rename a file or a folder
~~~~~~~~~~~~~~~~~~~~~~~~~

.. code:: python

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

195

richardARPANET's avatar
richardARPANET committed
196 197
~

richardARPANET's avatar
richardARPANET committed
198
.. _`https://code.richard.do/richardARPANET/mega.py`: https://code.richard.do/richardARPANET/mega.py
richardARPANET's avatar
richardARPANET committed
199 200
.. _`https://github.com/meganz/sdk`: https://github.com/meganz/sdk

richardARPANET's avatar
richardARPANET committed
201 202
.. |Build Status| image:: https://travis-ci.org/richardARPANET/mega.py.png?branch=master
   :target: https://travis-ci.org/richardARPANET/mega.py
richardARPANET's avatar
richardARPANET committed
203 204
.. |Downloads| image:: https://pypip.in/d/mega.py/badge.png
   :target: https://crate.io/packages/mega.py/