Package: pyrtlsdr
pyrtlsdrA Python wrapper for librtlsdr (a driver for Realtek RTL2832U based SDR's)Descriptionpyrtlsdr is a simple Python interface to devices supported by the RTL-SDR project, which turns certain USB DVB-T dongles
employing the Realtek RTL2832U chipset into low-cost, general purpose software-defined radio receivers. It wraps many of the
functions in thelibrtlsdr libraryincluding asynchronous read support
and also provides a more Pythonic API.LinksDocumentation:https://pyrtlsdr.readthedocs.io/Releases:https://pypi.org/project/pyrtlsdr/Source code and project home:https://github.com/pyrtlsdr/pyrtlsdrReleases forlibrtlsdr:https://github.com/librtlsdr/librtlsdr/releasesInstallationpyrtlsdr can be installed by downloading the source files and runningpython setup.py install, or usingpipandpip install pyrtlsdr.Full installation (recommended)New in version 0.3.0On most platforms, thelibrtlsdrbinaries may be also installed with thepyrtlsdrlibpackage.  This new feature shoulddrasticallysimplify the installation process (especially for Windows).This can be done by installingpyrtlsdrlibseparately (via pip) or for simplicity, both can be installed at once via:pipinstallpyrtlsdr[lib]If errors are encountered with thepyrtlsdrlibintegration (during installation or package import),
you may want to ensure you have the latest versions of both:pipinstall--upgradepyrtlsdr[lib]UsageAll functions in librtlsdr are accessible via librtlsdr.py and a Pythonic interface is available in rtlsdr.py (recommended).
Some documentation can be found in docstrings in the latter file.ExamplesSimple way to read and print some samples:fromrtlsdrimportRtlSdrsdr=RtlSdr()# configure devicesdr.sample_rate=2.048e6# Hzsdr.center_freq=70e6# Hzsdr.freq_correction=60# PPMsdr.gain='auto'print(sdr.read_samples(512))Plotting the PSD with matplotlib:frompylabimport*fromrtlsdrimport*sdr=RtlSdr()# configure devicesdr.sample_rate=2.4e6sdr.center_freq=95e6sdr.gain=4samples=sdr.read_samples(256*1024)sdr.close()# use matplotlib to estimate and plot the PSDpsd(samples,NFFT=1024,Fs=sdr.sample_rate/1e6,Fc=sdr.center_freq/1e6)xlabel('Frequency (MHz)')ylabel('Relative power (dB)')show()Resulting Plot:See the files 'demo_waterfall.py' and 'test.py' for more examples.Handling multiple devices:(added in v2.5.6)fromrtlsdrimportRtlSdr# Get a list of detected device serial numbers (str)serial_numbers=RtlSdr.get_device_serial_addresses()# Find the device index for a given serial numberdevice_index=RtlSdr.get_device_index_by_serial('00000001')sdr=RtlSdr(device_index)# Or pass the serial number directly:sdr=RtlSdr(serial_number='00000001')NoteMost devices by default have the same serial number: '0000001'. This can be set
to a custom value by using thertl_eepromutility packaged withlibrtlsdr.Experimental featuresTwo new submodules are available for testing:rtlsdraio, which adds native Python 3 asynchronous support (asyncio module), andrtlsdrtcpwhich adds a TCP server/client for accessing a device over the network. See the respective modules in the rtlsdr folder for more details and feel free to test and report any bugs!rtlsdraioNote that the rtlsdraio module is automatically imported and addsstream()andstop()methods to the normalRtlSdrclass. It also requires the newasync/awaitsyntax introduced in Python 3.5+.The syntax is basically:importasynciofromrtlsdrimportRtlSdrasyncdefstreaming():sdr=RtlSdr()asyncforsamplesinsdr.stream():# do something with samples# ...# to stop streaming:awaitsdr.stop()# donesdr.close()loop=asyncio.get_event_loop()loop.run_until_complete(streaming())rtlsdrtcpTheRtlSdrTcpServerclass is meant to be connected physically to an SDR dongle and communicate with an instance ofRtlSdrTcpClient. The client is intended to function as closely as possible to the base RtlSdr class (as if it had a physical dongle attached to it).Both of these classes have the same arguments as the baseRtlSdrclass with the addition ofhostnameandport:server=RtlSdrTcpServer(hostname='192.168.1.100',port=12345)server.run_forever()# Will listen for clients until Ctrl-C is pressed# On another machine (typically)client=RtlSdrTcpClient(hostname='192.168.1.100',port=12345)client.center_freq=2e6data=client.read_samples()TCP Client ModeOn platforms where thelibrtlsdrlibrary cannot be installed/compiled, it is possible to import theRtlSdrTcpClientonly by setting the environment variable"RTLSDR_CLIENT_MODE"to"true". If this is set, no other modules will be available.Feature added in v0.2.4DependenciesWindows/Linux/OSXPython 2.7.x/3.3+librtlsdrOptional: NumPy (wraps samples in a more convenient form)matplotlib is also useful for plotting data. The librtlsdr binaries (rtlsdr.dll in Windows and librtlsdr.so in Linux)
should be in the pyrtlsdr directory, or a system path. Note that these binaries may have additional dependencies.TodoThere are a few remaining functions in librtlsdr that haven't been wrapped yet. It's a simple process if there's an additional
function you need to add support for, and please send a pull request if you'd like to share your changes.TroubleshootingSome operating systems (Linux, OS X) seem to result in libusb buffer issues when performing small reads. Try reading 1024
(or higher powers of two) samples at a time if you have problems.librtlsdr import errorsFirst try upgradingpyrtlsdrand using thepyrtlsdrlibhelper package described above.In cases where that isn't feasible:Windows: Make sure all the librtlsdr DLL files (librtlsdr.dll, libusb-1.0.dll) are in your system path, or the same folder
as this README file. Also make sure you have all oftheirdependencies (e.g. libgcc_s_dw2-1.dll or possibly the Visual Studio runtime files). If rtl_sdr.exe
works, then you should be okay. Also note that you can't mix the 64 bit version of Python with 32 bit builds of librtlsdr, and vice versa.Linux: Make sure your LD_LIBRARY_PATH environment variable contains the directory where the librtlsdr.so.0 library is located. You can do this in a shell with (for example):export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib. Seethis issuefor more details.LicenseAll of the code contained here is licensed by the GNU General Public License v3.CreditCredit to dbasden for his earlier wrapperpython-librtlsdrand all the
contributors on GitHub.Copyright (C) 2013 by Rogerhttps://github.com/pyrtlsdr/pyrtlsdr