There could be several ways to add security to any such communication mechanism. Here are two solutions that I could think of right now:
- Use TLS/SSL wrappers for socket objects
- Use end to end encryption
As Python is running both on your server and the Raspberry, each method is very simple to implement.
This is an example for SSL/TLS socket. Also, I'll strongly advise on using an IoT-oriented communication protocol like MQTT, which also provides TLS/SSL security, for sensors' data acquisition.