pyrtlsdr
A Python wrapper for librtlsdr (a driver for Realtek RTL2832U based SDR's)
Science Score: 23.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
○.zenodo.json file
-
○DOI references
-
○Academic publication links
-
✓Committers with academic emails
1 of 21 committers (4.8%) from academic institutions -
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (14.1%) to scientific vocabulary
Repository
A Python wrapper for librtlsdr (a driver for Realtek RTL2832U based SDR's)
Basic Info
Statistics
- Stars: 664
- Watchers: 53
- Forks: 123
- Open Issues: 53
- Releases: 13
Metadata Files
README.md
pyrtlsdr
A Python wrapper for librtlsdr (a driver for Realtek RTL2832U based SDR's)
Description
pyrtlsdr 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 the librtlsdr library including asynchronous read support and also provides a more Pythonic API.
Links
- Documentation:
- https://pyrtlsdr.readthedocs.io/
- Releases:
- https://pypi.org/project/pyrtlsdr/
- Source code and project home:
- https://github.com/pyrtlsdr/pyrtlsdr
- Releases for
librtlsdr:- https://github.com/librtlsdr/librtlsdr/releases
Installation
pyrtlsdr can be installed by downloading the source files and running python setup.py install, or using pip and
pip install pyrtlsdr.
Full installation (recommended)
New in version 0.3.0
On most platforms, the librtlsdr binaries may be also installed with the pyrtlsdrlib package. This new feature should drastically simplify the installation process (especially for Windows).
This can be done by installing pyrtlsdrlib separately (via pip) or for simplicity, both can be installed at once via:
bash
pip install pyrtlsdr[lib]
If errors are encountered with the pyrtlsdrlib integration (during installation or package import),
you may want to ensure you have the latest versions of both:
bash
pip install --upgrade pyrtlsdr[lib]
Usage
All 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.
Examples
Simple way to read and print some samples:
```python from rtlsdr import RtlSdr
sdr = RtlSdr()
configure device
sdr.samplerate = 2.048e6 # Hz sdr.centerfreq = 70e6 # Hz sdr.freq_correction = 60 # PPM sdr.gain = 'auto'
print(sdr.read_samples(512)) ```
Plotting the PSD with matplotlib:
```python from pylab import * from rtlsdr import *
sdr = RtlSdr()
configure device
sdr.samplerate = 2.4e6 sdr.centerfreq = 95e6 sdr.gain = 4
samples = sdr.read_samples(256*1024) sdr.close()
use matplotlib to estimate and plot the PSD
psd(samples, NFFT=1024, Fs=sdr.samplerate/1e6, Fc=sdr.centerfreq/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) ```python from rtlsdr import RtlSdr
Get a list of detected device serial numbers (str)
serialnumbers = RtlSdr.getdeviceserialaddresses()
Find the device index for a given serial number
deviceindex = RtlSdr.getdeviceindexby_serial('00000001')
sdr = RtlSdr(device_index)
Or pass the serial number directly:
sdr = RtlSdr(serial_number='00000001') ```
Note
Most devices by default have the same serial number: '0000001'. This can be set
to a custom value by using the rtl_eeprom utility packaged with librtlsdr.
Experimental features
Two new submodules are available for testing: rtlsdraio, which adds native Python 3 asynchronous support (asyncio module), and rtlsdrtcp which 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!
rtlsdraio
Note that the rtlsdraio module is automatically imported and adds stream() and stop() methods to the normal RtlSdr class. It also requires the new async/await syntax introduced in Python 3.5+.
The syntax is basically:
```python import asyncio from rtlsdr import RtlSdr
async def streaming(): sdr = RtlSdr()
async for samples in sdr.stream():
# do something with samples
# ...
# to stop streaming:
await sdr.stop()
# done
sdr.close()
loop = asyncio.geteventloop() loop.rununtilcomplete(streaming()) ```
rtlsdrtcp
The RtlSdrTcpServer class is meant to be connected physically to an SDR dongle and communicate with an instance of RtlSdrTcpClient. 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 base RtlSdr class with the addition of hostname and port:
```python
server = RtlSdrTcpServer(hostname='192.168.1.100', port=12345)
server.run_forever()
Will listen for clients until Ctrl-C is pressed
python
On another machine (typically)
client = RtlSdrTcpClient(hostname='192.168.1.100', port=12345) client.centerfreq = 2e6 data = client.readsamples() ```
TCP Client Mode
On platforms where the librtlsdr library cannot be installed/compiled, it is possible to import the RtlSdrTcpClient only 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.4
Dependencies
- Windows/Linux/OSX
- Python 2.7.x/3.3+
- librtlsdr
- Optional: 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.
Todo
There 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.
Troubleshooting
- Some 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 errors
First try upgrading pyrtlsdr and using the pyrtlsdrlib helper 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 of their dependencies (e.g. libgccsdw2-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 LDLIBRARYPATH 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. See this issue for more details.
License
All of the code contained here is licensed by the GNU General Public License v3.
Credit
Credit to dbasden for his earlier wrapper python-librtlsdr and all the contributors on GitHub.
Copyright (C) 2013 by Roger https://github.com/pyrtlsdr/pyrtlsdr
Owner
- Name: pyrtlsdr
- Login: pyrtlsdr
- Kind: organization
- Repositories: 2
- Profile: https://github.com/pyrtlsdr
GitHub Events
Total
- Issues event: 2
- Watch event: 34
- Issue comment event: 6
- Fork event: 5
Last Year
- Issues event: 2
- Watch event: 34
- Issue comment event: 6
- Fork event: 5
Committers
Last synced: over 2 years ago
Top Committers
| Name | Commits | |
|---|---|---|
| nocarryr | m****t@n****m | 309 |
| Roger | R****r@R****) | 11 |
| Roger | r****- | 10 |
| Roger Bacchus | r****t@g****m | 10 |
| Roger | r****t@g****m | 6 |
| Al | al@e****m | 5 |
| Ian Daniher | i****r@g****m | 3 |
| Roger | r****t@g****m | 3 |
| daumiller | d****r@g****m | 2 |
| superkuh | g****b@s****m | 2 |
| Brady Langdale | b****e@g****m | 2 |
| Frank Werner-Krippendorf | w****f@g****m | 1 |
| Daniele Forsi | i****x@g****m | 1 |
| Robert Schütz | r****z@s****e | 1 |
| Jack Ferguson | j****3@l****m | 1 |
| Xie Yanbo | x****o@g****m | 1 |
| Patrick Butler | p****r@k****g | 1 |
| Jonathan Warren | A****1 | 1 |
| Roger Bacchus | n****e@n****m | 1 |
| Tim Gates | t****s@i****m | 1 |
| Xavier Olive | 1****e | 1 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: about 1 year ago
All Time
- Total issues: 94
- Total pull requests: 41
- Average time to close issues: 4 months
- Average time to close pull requests: 4 months
- Total issue authors: 75
- Total pull request authors: 16
- Average comments per issue: 4.3
- Average comments per pull request: 3.73
- Merged pull requests: 32
- Bot issues: 0
- Bot pull requests: 1
Past Year
- Issues: 4
- Pull requests: 3
- Average time to close issues: about 1 hour
- Average time to close pull requests: 28 minutes
- Issue authors: 4
- Pull request authors: 3
- Average comments per issue: 0.5
- Average comments per pull request: 1.67
- Merged pull requests: 1
- Bot issues: 0
- Bot pull requests: 1
Top Authors
Issue Authors
- wgaylord (7)
- JAbelP (2)
- nocarryr (2)
- wangshujun1 (2)
- witc (2)
- hfwang132 (2)
- natiya (2)
- CrashBandibug14 (2)
- weathon (2)
- Xie-Tian (2)
- ImNiceButActuallyNot (2)
- hshahbodaghkhan (1)
- PinkiMan (1)
- clarktristan (1)
- sortofasian (1)
Pull Request Authors
- nocarryr (25)
- fergusonjack (2)
- evanmayer (2)
- itdaniher (2)
- dependabot[bot] (2)
- atkinson (2)
- wgaylord (1)
- bradylangdale (1)
- timgates42 (1)
- dotlambda (1)
- hazrmard (1)
- Michael-fore (1)
- hb9fxq (1)
- xoolive (1)
- dforsi (1)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- pypi 7,082 last-month
- Total dependent packages: 6
- Total dependent repositories: 55
- Total versions: 15
- Total maintainers: 2
pypi.org: pyrtlsdr
A Python wrapper for librtlsdr (a driver for Realtek RTL2832U based SDR's)
- Homepage: https://github.com/pyrtlsdr/pyrtlsdr
- Documentation: https://pyrtlsdr.readthedocs.io/
- License: GPLv3
-
Latest release: 0.3.0
published almost 3 years ago
Rankings
Dependencies
- Sphinx >=2.3.1
- docutils >=0.17
- linkify-it-py *
- myst-parser *
- sphinx_rtd_theme 1.0.0rc1
- MatteoH2O1999/setup-python v1 composite
- actions/checkout v2 composite
- actions/download-artifact v2 composite
- actions/setup-python v2 composite
- actions/upload-artifact v2 composite
- MatteoH2O1999/setup-python v1 composite
- actions/checkout v2 composite
- actions/setup-python v2 composite