Skip to main content

DHT_PI

=======================

Simplified & Modernized fork of Adafruit's Deprecated Python DHT Sensor Library, limited to currently supported versions of Raspberry PI (Pi 2+, but create an issue if you want a Pi 1 port). Provides a simple, safe, and typed reading of temperature and humidity from DHT11, DHT22, AND AM2302 sensors via GPIO pins.

For modern support by Adafruit, see their CircuitPython libraries.

However, this simple library following modern python packaging was created because CircuitPython is a convoluted Kitchen sink that is difficult to use. I wouldn't recommend it.

This fork is not affiliated with Adafruit in any way. All copyrights belong to them except for heavily modified or new code.

Installation

You can install from Pypi using your favorite package manager (such as pip or uv). I recommend using uv

uv add dht_pi
# pip install dht_pi

Designed for Python 3.11+. Create an issue or PR if you want support/port for earlier 3.X versions. We don't even build for them.

Usage

There is a safe class-based endpoint and a slightly less safe functional endpoint.

from dht_pi import Sensor, DHT11 # or DHT22, AM2302 or #SensorType and do SensorType.DHT11

GPIO_PIN = 12 # Or whichever GPIO PIN you used for the data link

sensor = Sensor(sensor_type=DHT11, pin=GPIO_PIN) 
reading = sensor.read_retry() 
# Better to use `sensor.read_retry` instead of `sensor.read`, which gives `None` readings much more readily.
print(reading.humidity, reading.temperature)

# Equivalent, but easy to mix up the order:
humidity, temperature = sensor.read_retry()
print(humidity, temperature)

Functional endpoint:

from dht_pi import SensorType, read_retry, read

GPIO_PIN = 12 # Or whichever GPIO PIN you used for the data link
reading = read_retry(sensor=SensorType.DHT22, pin=GPIO_PIN)

# Most dangerous:
humidity, temperature = read(sensor=SensorType.DHT22.value, pin=GPIO_PIN)

Running directly on a Raspberry Pi

Ensure that your Pi can compile and download Python extensions (such as with pip). Modern Raspbian ships with Python 3.11 and pip. I would still recommend uv (Technically, you can even install uv via pip). Then simply run:

Upcoming:

  • Shell scripts.

Note: Below is from the original repo

Original Author

Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit!

Written by Tony DiCola for Adafruit Industries.

MIT license, all text above must be included in any redistribution (?: The license doesn't mention this, but I left this part in here as well as links to Adafruit)

Metadata

Release files for dht-pi 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dht-pi 0.1.3
File Size Uploaded
dht_pi-0.1.3.tar.gz 10.6 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for dht-pi 0.1.3
File
dht_pi-0.1.3-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.whl CPython 3.14 CPython 3.14 Linux glibc 2.17+ ARM64 Details
dht_pi-0.1.3-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.whl CPython 3.13 CPython 3.13 Linux glibc 2.17+ ARM64 Details
dht_pi-0.1.3-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.whl CPython 3.12 CPython 3.12 Linux glibc 2.17+ ARM64 Details
dht_pi-0.1.3-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.whl CPython 3.11 CPython 3.11 Linux glibc 2.17+ ARM64 Details

Total release size: 96.2 kB

Release files / dht_pi-0.1.3.tar.gz

Download URL dht_pi-0.1.3.tar.gz
Size 10.6 kB
Tags Source
SHA-256 checksum
How to use checksums
b013d12bfbce895cfbe1169cc1d04f1c22d07dd37b6b47cd21d92f747a287abe
BLAKE2b-256 checksum
How to use checksums
a98e263d5e968b18625408ac6150a1ec86131e88858a981ceb2f5e3f7e8fc2fb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.8.22

Release files / dht_pi-0.1.3-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL dht_pi-0.1.3-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 21.4 kB
Tags CPython 3.14 Linux glibc 2.17+ ARM64
SHA-256 checksum
How to use checksums
5210f216379d3eb4db9fc2bcc1acd5c0782b105e9fefe1aa112dcdd0c2b8de0b
BLAKE2b-256 checksum
How to use checksums
f0b07e31ec9b9e32a113088155aea4c1de5e1c6a6e04b07cafe8e2c613644f28
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.8.22

Release files / dht_pi-0.1.3-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL dht_pi-0.1.3-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 21.4 kB
Tags CPython 3.13 Linux glibc 2.17+ ARM64
SHA-256 checksum
How to use checksums
f541beaa08838a8a550f6304c284205bb754271d573154906775bd3c34a48559
BLAKE2b-256 checksum
How to use checksums
ad93e12562b4c2c09fc26f7e2fa5f3d629e9ec5eac3fe82e4ef39a7c96d7bd90
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.8.22

Release files / dht_pi-0.1.3-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL dht_pi-0.1.3-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 21.4 kB
Tags CPython 3.12 Linux glibc 2.17+ ARM64
SHA-256 checksum
How to use checksums
09e35c55b06ddc32099c212627576823c15fa091225eea8e3a026de5408de3a6
BLAKE2b-256 checksum
How to use checksums
b2c809440222324ff64d69207b95295fb4ee1365ee19ac4aaaca57d0b4c21a91
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.8.22

Release files / dht_pi-0.1.3-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL dht_pi-0.1.3-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 21.3 kB
Tags CPython 3.11 Linux glibc 2.17+ ARM64
SHA-256 checksum
How to use checksums
e36ecb865203ad5651cb80bb04e141e4e498c3388f4825acd7696817c8f6d464
BLAKE2b-256 checksum
How to use checksums
92142436babddbf9dfeeacf8661790400ac3306726d794a07d2666dd7d638d8b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.8.22

Release history Release notifications | RSS feed

This release

0.1.3 This release

5 release files

0.1.2

5 release files

0.1.1

5 release files

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page