High performance binary data

S

Steve

I want to ready binary data from a udp socket effeciently as possible
in python. I know of the struct package but do people have any tips
when dealing with binary data in python? Is there a library or api
that is faster when dealing with binary data. I am looking for a any
one with experience or ideas on the subject. Pointers any one?

Thanks
Steve
 
M

Marc 'BlackJack' Rintsch

I want to ready binary data from a udp socket effeciently as possible
in python. I know of the struct package but do people have any tips
when dealing with binary data in python? Is there a library or api
that is faster when dealing with binary data. I am looking for a any
one with experience or ideas on the subject. Pointers any one?

I don't know if it is faster, but maybe constructing objects with
the `ctypes` module let you write more readable code as you can treat and
access C ``struct``\s like objects.

For the "fast" part of the question you might consider actually measuring
your program, as the task may be I/O bound i.e. Python may be faster than
the data comes in regardless of which module, `struct` or `ctypes`, you
use to tear apart and access the data.

Ciao,
Marc 'BlackJack' Rintsch
 
N

Nick Craig-Wood

Steve said:
I want to ready binary data from a udp socket effeciently as possible
in python. I know of the struct package but do people have any tips
when dealing with binary data in python? Is there a library or api
that is faster when dealing with binary data. I am looking for a any
one with experience or ideas on the subject. Pointers any one?

Check out construct: http://construct.wikispaces.com/
 
S

sturlamolden

I want to ready binary data from a udp socket effeciently as possible
in python. I know of the struct package but do people have any tips
when dealing with binary data in python? Is there a library or api
that is faster when dealing with binary data. I am looking for a any
one with experience or ideas on the subject. Pointers any one?

I would recommend NumPy for manipulating binary data. It is primarily
intended for numerics, but it is excellent for dealing with any kind
of binary data as well. It can handle mutable buffers of any kind of
integer or float, as well as arrays of C-like structs (record arrays
in numpy). You can typecast and create subarrays without copying any
data, simply by providing a new "view" into the buffer. You can also
get access to strided subsections without creating copies. And it is
very fast.

www.scipy.org
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top