By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,235 Members | 1,022 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,235 IT Pros & Developers. It's quick & easy.

High performance binary data

P: n/a
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

Aug 10 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Fri, 10 Aug 2007 00:26:54 +0000, Steve wrote:
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
Aug 10 '07 #2

P: n/a
Steve <st*********@gmail.comwrote:
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/

--
Nick Craig-Wood <ni**@craig-wood.com-- http://www.craig-wood.com/nick
Aug 10 '07 #3

P: n/a
On Aug 10, 2:26 am, Steve <steve.mo...@gmail.comwrote:
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

Aug 10 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.