Warning The software in this article is highly outdated, unsupported, and most certainly useless with the current state of Dropbox.
simpledropbox is a python package. Its goal is to allow the execution
of some (hopefully the most useful) operations on dropbox without
actually installing dropbox.
When installed on a server, dropbox can be useful for many things.
It does however eat a lot of memory. It can also takes forever to start on trees containing a few dozen thousands files.
Sample memory usage taken from a
top on a server I manage::
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ CODE DATA COMMAND 31857 dropbox- 20 0 205m 105m 3332 S 0.0 6.2 54:58.04 984 199m dropbox
This library makes it easy to list, delete, add, rename, … files on dropbox.
I am aware of the official API that can be found on bitbucket. Sadly, in its current form, it seem very oriented toward building “applications” and doesn’t seems to be available to the general public (it’s been two days now and I haven’t received a reply yet).
So I wrote this because I needed it now.
How it works
This library utilizes Dropbox’s web API, the same your web browser uses.
As such, if they change the layout, this library could stop working.
This software is released under the Apache License, version 2.0.
Not much documentation right now, sorry. If anyone other than me start using this, maybe I’ll write some.
For now this can be installed the “usual ways”, namely using
$ pip install hg+http://bitbucket.org/greyw/simpledropbox
Source and files
You can browse the source on simpledropbox’s bitbucket repository.
You can clone the source:
$ hg clone http://bitbucket.org/greyw/simpledropbox/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
#!/usr/bin/env python import os from getpass import getpass import pytz import logging logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s") from simpledropbox import SimpleDropbox, SdFile db_user = raw_input(u'Your dropbox login: ') db_pass = getpass(u'Your dropbox password: ') sdb = SimpleDropbox(db_user, db_pass) sdb.login() sdb.put(u'/readmes/readme.txt', 'Thanks for reading me') inf, data = sdb.get(u'/readmes/readme.txt') print "File readmes/readme.txt contains: '%s'" % data est = pytz.timezone('America/Montreal') files = sdb.ls(u'/Photos/Sample Album', filter=SdFile) for sdf in files: # Get more information about the file sdf = sdb.stat(sdf) print u'%s (%d): %s' % ( os.path.basename(sdf.path), sdf.size, sdf.modified.astimezone(est).strftime('%Y-%m-%d %H:%M:%S %Z') )
Your dropbox login: my-dropbox-login Your dropbox password: 2010-06-24 16:53:02,101 - INFO - Logging in 2010-06-24 16:53:03,282 - INFO - put /readmes/readme.txt 2010-06-24 16:53:04,549 - INFO - stat u'/readmes/readme.txt' 2010-06-24 16:53:04,550 - INFO - ls u'/readmes' 2010-06-24 16:53:05,013 - INFO - get /readmes/readme.txt File readmes/readme.txt contains: 'Thanks for reading me' 2010-06-24 16:53:05,470 - INFO - ls u'/Photos/Sample Album' 2010-06-24 16:53:06,004 - INFO - head /Photos/Sample Album/Boston City Flow.jpg Boston City Flow.jpg (339773): 2010-06-24 16:53:06 EDT 2010-06-24 16:53:06,355 - INFO - head /Photos/Sample Album/Costa Rican Frog.jpg Costa Rican Frog.jpg (354633): 2010-06-24 16:53:06 EDT 2010-06-24 16:53:06,839 - INFO - head /Photos/Sample Album/Pensive Parakeet.jpg Pensive Parakeet.jpg (480098): 2010-06-24 16:53:07 EDT