views:

65

answers:

1

Recall those applications that provide the option to "Send usage statistics to help improve X" during the installation? I presume it collects certain patterns of usage and sends it back to the server. Back at the server, there may be some sort of mining going on.

Is there a Python library to do this .. at least from the client part? (other than manually having to code it up using urllib, for instance)

+2  A: 

Sending and receiving logging events across a network

From the docs:

import logging, logging.handlers

rootLogger = logging.getLogger('')
rootLogger.setLevel(logging.DEBUG)
socketHandler = logging.handlers.SocketHandler('localhost',
                    logging.handlers.DEFAULT_TCP_LOGGING_PORT)
# don't bother with a formatter, since a socket handler sends the event as
# an unformatted pickle
rootLogger.addHandler(socketHandler)

# Now, we can log to the root logger, or any other logger. First the root...
logging.info('Jackdaws love my big sphinx of quartz.')
# ...

You can also find there the code for receiving end.

In your case it might be more appropriate to use logging.handlers.DatagramHandler on a non-root logger e.g., logging.getLogger('usage').

J.F. Sebastian