Is Python a good choice for a data logger?

Chris Angelico rosuav at gmail.com
Tue Dec 8 09:17:42 EST 2015


On Wed, Dec 9, 2015 at 12:30 AM,  <villascape at gmail.com> wrote:
> Is Python a good choice for the following:
>
> 1) The data-loggers to pole data and/or receive data from the UDP devices and send the data to the server?
>
> 2) The daemon/application running on the server which receives the data from the data-loggers, and stores it in the database?
>
>
> If Python is a good choice, please explain why.
>

Yep! Both of these applications are going to spend virtually all their
time *waiting*. That means you don't have to stress about performance,
and can concentrate on writing code in the easiest and cleanest way
possible. To my mind, that says either Python or Pike; both languages
have excellent networking libraries, but in this case, Python
definitely takes the edge, because you already have broad familiarity
with it.

> Also, please provide a very high level strategy to implement (I am not asking for script, but just enough so I can initially focus on  learning those parts of Python).
>

Start with the socket module:

https://docs.python.org/3/library/socket.html

Get to know something of how TCP/IP works, if you don't already. Then
once you're ready to do your actual implementation, since you've
considered using HTTP, I would suggest looking into the third-party
'requests' library for the HTTP clients (you can do everything with
the standard library if you prefer, but you owe it to yourself to at
least have a quick _look_ at requests), and one of the standard web
frameworks for the server (personally, I use Flask, but any would do).
You'll probably want a database back end to store the actual content;
I strongly recommend PostgreSQL, which you can access from Python
using psycopg2. If you don't like hand-writing SQL, you could use
something like SQLAlchemy as middleware; otherwise, direct use of
psycopg2 works just fine.

Every part in this can be replaced without affecting the rest, but if
I were doing this kind of job, these would be the tools I'd first
reach for.

requests: http://requests.readthedocs.org/en/latest/
Flask: http://flask.pocoo.org/docs/
psycopg2: http://initd.org/psycopg/docs/
SQLAlchemy: http://www.sqlalchemy.org/

You asked for a "very high level" strategy. This is so high level it's
practically in LEO, but it's a start :)

ChrisA



More information about the Python-list mailing list