I'm writing code (Python 3) that collects data on a small IOT device and uploads it to a database on AWS. Currently the data is sent by parsing it into a json string and sending it via post request. There can be quite a lot of data at times, and I'm wondering if I can send it in compressed form using a post request.
What I don't want to do is take the data, compress it to a file, then read that file's raw data into a string, and place that string in the JSON. It would be a waste to save a file and immediately read from it.
Is there a way to compress data directly into a string of raw data, and send the compressed string as opposed to compressing into a file and reading it?
I need a lossless compression format, hopefully something that's not too resource intensive to compress/decompress. A .npy compression would be especially nice.
You seem to have binary data since you mention npy.
Just send the binary data in the POST body.
If you need to compress signals then that is a different problem.
Most measurements are not very compressible losslessly. 
You might need to lower the precision of your floats or do some signal processing on device like low pass filtering noise, bandpass limit, delta compression.
For good results there are powerful lossy quantization algorithms like mp3 is using. But those are complex to understand and get right.
Compressing data to string for json post without saving files