Metadata-Version: 2.4
Name: scentience
Version: 0.1.0
Summary: Python client for Scentience olfaction instruments over BLE Bluetooth
Project-URL: Documentation, https://scentience.github.io/docs-api/ble-api
Project-URL: Repository, https://github.com/scentience/scentience-pypi
License: MIT License
        
        Copyright (c) 2026 Scentience
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: ble,bluetooth,chemical-sensing,olfaction,scentience,sensors
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering
Classifier: Topic :: System :: Hardware
Requires-Python: >=3.8
Requires-Dist: bleak>=0.21.0
Description-Content-Type: text/markdown

# scentience

Python client for [Scentience](https://scentience.github.io) olfaction instruments over BLE Bluetooth.

## Installation

```bash
pip install scentience
```

## Requirements

- Python 3.8+
- Bluetooth 4.0+ adapter
- A Scentience developer API key (obtain from the Scentience portal)

## Quick start

```python
import scentience as scn

# Initialize with your developer API key
device = scn.ScentienceDevice(api_key="YOUR_API_KEY")

# Connect via BLE (scans for the first available Scentience device)
device.connect_ble(char_uuid="YOUR_CHAR_UUID")

# Take a single reading
data = device.sample_ble()
print(data)

# Start continuous streaming (non-blocking)
device.stream_ble(callback=lambda d: print(d))

# Stop streaming and disconnect
device.stop_stream()
device.disconnect()
```

## Targeting a specific device

Pass the device UID (serial number or BLE address) to connect to a particular instrument:

```python
device.connect_ble(char_uuid="YOUR_CHAR_UUID", device_uid="YOUR_DEVICE_UID")
```

## Context manager

```python
with scn.ScentienceDevice(api_key="YOUR_API_KEY") as device:
    device.connect_ble(char_uuid="YOUR_CHAR_UUID")
    data = device.sample_ble()
```

## Response payload

`sample_ble()` and the streaming callback receive a dict that may contain:

| Key | Description |
|-----|-------------|
| `UID` | Device serial number |
| `TIMESTAMP` | Reading timestamp |
| `ENV_temperatureC` | Ambient temperature (°C) |
| `ENV_humidity` | Relative humidity (%) |
| `ENV_pressureHpa` | Barometric pressure (hPa) |
| `BATT_health` | Battery health |
| `BATT_v` | Battery voltage |
| `BATT_charge` | Battery charge (%) |
| `BATT_time` | Estimated battery time remaining |
| `STATUS_opuA` | Operational status |
| `CO2`, `NH3`, `NO`, `NO2`, `CO`, `C2H5OH` | Chemical compounds (non-zero only) |
| `H2`, `CH4`, `C3H8`, `C4H10`, `H2S`, `HCHO`, `SO2`, `VOC` | Chemical compounds (non-zero only) |

## Logging and export

All readings from `sample_ble()` and `stream_ble()` are automatically buffered in memory.

```python
# Access the in-memory log at any time
print(device.log)          # list of dicts

# Export to JSON
device.export_json("readings.json")

# Export to CSV
device.export_csv("readings.csv")

# Clear the buffer
device.clear_log()
```

The CSV uses `UID` and `TIMESTAMP` as the first columns (when present), followed by all other fields in alphabetical order.  Readings that are missing a field are written with an empty value for that column.

## API reference

See the full [BLE API documentation](https://scentience.github.io/docs-api/ble-api).

## License

MIT
