Metadata-Version: 2.4
Name: biostarPython
Version: 0.7.1.0
Summary: Python client for Suprema GSDK with included callable classes.
Home-page: https://github.com/gcartlidge/biostarPython
Author: SupremaUK
Author-email: gcartlidge@supremainc.com
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.15
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: grpcio>=1.85.4
Requires-Dist: protobuf<8,>=7.35.1
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: license-file
Dynamic: requires-dist
Dynamic: requires-python
Dynamic: summary

# Python Client for Suprema GSDK

This is the pip distributable version of the Suprema GSDK Python client, which makes it easier to interact with the GSDK.<br>

The examples from the [Suprema GSDK Wiki](https://supremainc.github.io/g-sdk/) can be used, but with this package, all dependencies are handled via PIP. The EventCode .json file and device list are also initialized automatically when importing package.<br>
### Tips
On some clients (Particularly android) the  EventCode json can sometimes not be loaded. If this happens, an error will display. You can then call 

```python
JsonFileLocation = "C:\\biostarPython\\event_code.json"
biostarPython.initCodeMap(JsonFileLocation)
```
To check Event codes, call 
```python
biostarPython.getEventString(eventCode,subCode)
```
To check device type, call 
```python
biostarPython.deviceType[deviceCode]
```
I'd also recommend checking out [Advanced Installer](https://www.advancedinstaller.com/)! They allow free licences for open-source projects and the features of the program licences are well worth it!

## How to use the rest of the classes.

All classes that can be used are imported under the biostarPython package.
The ones currently written are:<br>
**GatewayClient, ConnectSvc, DeviceSvc, FaceSvc, FingerSvc, StatusSvc, UserSvc, DisplaySvc, AdminSvc, WiegandSvc, TimeSvc, CardSvc, EventSvc, NetworkSvc, ServerSvc, SystemSvc, DoorSvc, RS485Svc, AuthSvc, AccessSvc, ScheduleSvc, ActionSvc, TNASvc, OperatorSvc, LockZoneSvc, TimedAPBZoneSvc, APBZoneSvc, IntrusionZoneSvc, FireZoneSvc, InterlockZoneSvc, UDPSvc, DeviceLicenseSvc, MasterAdminSvc, RTSPSvc, VOIPSvc, CertSvc, ConnectMasterSvc, DeviceNotifySvc, GatewaySvc, InputSvc, LiftSvc, LiftZoneSvc, LoginSvc, MasterSvc, TenantSvc, ThermalSvc & UDPMasterSvc**

All RPCs in the included proto files have wrappers. Availability depends on your gateway and device firmware.

With all of these services, they are a callable class underneath the biostarPython package. An example of initial setup with the GatewayClient and ConnectSvc is below:
For all of the functions below these services, they are formated with the first letter in lowercase, so to search a device would be searchDevice(), to get info would be getInfo().<br>
The guides on how to use these are present at the the  [GSDK Homepage](https://supremainc.github.io/g-sdk/)<br>
```python
# import the service duh!
import biostarPython as g
# connect to the gateway, get a channel, then funnel this through to the 
# services!
gateway = g.GatewayClient('127.0.0.1',4000,'ca.crt')
channel = gateway.getChannel()
connect = g.ConnectSvc(channel)
face = g.FaceSvc(channel)
network = g.NetworkSvc(channel)
# will return a list of devices visible on UDP
deviceInfo = connect.searchDevice(300) 
# needs IP address, port and SSL state
bs3 = connect.connect(connect.getConnInfo('192.168.0.50', 51211, False))
# 4 is the default scan threshold
face.scan(bs3,4)
#lets get and change an IP Config
existingConfig = network.getIPConfig(bs3)
existingConfig.useDHCP = False
existingConfig.IPAddress = '192.168.0.20'
network.setIPConfig(bs3, existingConfig)
```

All of the specific APIs can be found at the wiki Above.

### Closing gateway connections

Use `GatewayClient` as a context manager to close its gRPC channel automatically,
including when an operation raises an exception:

```python
with g.GatewayClient('127.0.0.1', 4000, 'ca.crt') as gateway:
    users = g.UserSvc(gateway.getChannel())
    print(users.getStatistic(deviceID))
```

For longer-lived clients, call `gateway.close()` explicitly when finished, ideally
in a `finally` block. Calling `close()` more than once is safe. Closing the channel
cancels active RPCs and subscriptions, including those using service instances
created from that channel. It does not disconnect devices from the GSDK gateway.
After closure, `getChannel()` returns `None`; create a new `GatewayClient` to reconnect.

### Version 0.7.0.0 migration notes

Requires Python 3.10+, grpcio 1.85.4+, and protobuf 7.35.1+ (major version 7).
`TestSvc` has been removed with the retired Test service.

- `ConnectSvc.setConnectionMode`, `enableSSL`, and `disableSSL` now accept a single `deviceID`. Use `setConnectionModeMulti(deviceIDs, mode)`, `enableSSLMulti(deviceIDs)`, and `disableSSLMulti(deviceIDs)` for lists of devices.
- Corrected argument names: `DeviceSvc.resetConfigMulti(deviceIDs, withNetwork, withDB)`, `DeviceSvc.clearDBMulti(deviceIDs)`, `UserSvc.setJobCodeMulti(deviceIDs, userJobCodes)`, and `DisplaySvc.updateNoticeMulti(deviceIDs, notice)`.
- `UserSvc.getPartial` now takes `(deviceID, userIDs, infoMask)`. `UserSvc.deleteAllMulti` takes only `deviceIDs`; the previous `userIDs` argument was unused.
- `EventSvc.subscribe` accepts optional `deviceIDs` and `eventCodes`; `DoorSvc.lock` and `unlock` accept optional `normalizeTimer`; `TNASvc.getTNALog` accepts an optional `filter` message.
- All methods whose RPC response contains `deviceErrors` now return that protobuf collection, including existing multi-device methods that previously returned `None` or the complete response. Other new methods return the response's sole field when it has one, the complete response when it has several fields, and `None` for empty responses. Other existing return conventions are preserved.
- Importing the package no longer creates `GSDKlog.log`, installs a file handler, or sets a log level. Configure logging in your application as shown below.
- Server-streaming methods return the gRPC iterator. Master channel methods accept an iterator of protobuf messages as `requestIterator`; `MasterSvc.newCommandResponse`, `newRealtimeEvent`, `newDeviceStatus`, and `newRealtimeQR` construct those messages. MasterSvc exposes gateway channel RPCs; it does not run the gateway command-processing loop automatically.

For example, subscribe to QR/barcode notifications using an existing channel:

```python
notifications = g.DeviceNotifySvc(channel)
for scan in notifications.subscribeQRScan(queueSize=100, deviceIDs=[bs3]):
    print(scan.deviceID, scan.QRData)
```

### Per-device errors and logging

Multi-device RPCs can complete while individual devices fail. Methods whose responses
contain `deviceErrors` return that collection unchanged. Each entry contains
`deviceID`, `code`, and `msg`; an empty collection means no per-device errors were
reported. Gateway or transport failures still raise `grpc.RpcError`.

```python
errors = face.setConfigMulti(deviceIDs=[bs3], config=face.getConfig(bs3))
for error in errors:
    print(error.deviceID, error.code, error.msg)
```

This changes existing multi-device return values in version 0.7.0.0. Code that used
`result.deviceErrors` should now iterate over `result` directly. Callers that ignored
the return value continue to work, but should inspect it to detect partial failures.

The package uses the `biostarPython` logger with a `NullHandler`. Your application
controls log destinations, formatting, and levels. To enable file logging explicitly:

```python
import logging

logging.basicConfig(
    filename="GSDKlog.log",
    level=logging.INFO,
    format="%(asctime)s %(levelname)s %(name)s %(message)s",
)
```

Omit `filename` to log to the console. Existing application logging configurations
are preserved, and importing the package repeatedly does not add duplicate handlers.

### Regenerating protobuf bindings

From the repository root, install the development dependencies once:

```powershell
python -m pip install -r requirements-dev.txt
```

After updating the `.proto` files in `biostarPython/proto`, run:

```powershell
python scripts/regenerate_protos.py
```

The command finds all current proto files, generates Python, gRPC, and typing outputs
in a temporary directory, and fixes local imports to use `biostarPython.service`.
It updates `pythonOut`, `grpcOut`, and `pyiOut`, copies the Python and gRPC modules
into `service`, and removes obsolete generated files in those locations. Unrelated
files such as `__init__.py` are preserved. Typing outputs remain in `pyiOut`.

The full test suite then checks every RPC wrapper against the generated schemas.
If installation or validation fails, the previous generated files are restored and
the command exits with an error. New or removed RPCs may require corresponding
manual changes to `biostarPython/__init__.py` before regeneration can pass.

The generator version is pinned in `requirements-dev.txt`. When upgrading it, also
review the runtime requirements in `setup.py`. Generation runs locally and does
not contact a gateway or require hardware.

### changelog

- 0.7.0.0 - Added wrappers for all current RPCs, including DeviceNotify QR subscriptions and master services; corrected request mappings, arguments, and response fields; removed TestSvc and updated runtime requirements; exposed per-device errors consistently and moved logging configuration to the application.
- 0.6.5.0 - Updated proto files to 1.9.1 distribution of GSDK, added support for BioStation 3 Max, updated GRPC and Protobuf to latest.
- 0.6.0.0 - Updated proto files to 1.9.0 distribution of GSDK, added MasterAdminSvc, DeviceLicenseSvc, Support for multiple devices, Run Action, Lock Override, Door Mode Override, Realtime IO and User Override. 
- 0.4.0.2 - Updated proto files to 1.7.1 distribution of GSDK (Template only selection for FaceData and FaceConfig)
- 0.4.0.1 - Added UpdateSlideImages to DisplaySvc and added Fingerprint to TestSvc.
- 0.4.0.0 - Updated proto files to 1.7.0 (New Features, BEW3 support), added TestSvc (Waiting on support from device), fixed factoryDefault parameters.
- 0.3.0.5 - Added UDPSvc for changing IP config via UDP, Updated Proto generation to 1.6.0 version of GSDK.
- 0.3.0.2 - Fixed no response recieved from some user commands, also added newEventFilter()
          under event service, to create a new Filter.
- 0.3.0.0 - Support for BS3, VOIP, RTSP and Wiegand User ID
- 0.2.1.4 - Version Push
- 0.2.1.2 - Fixed issue with importing none existent package
- 0.2.1.0 - Addes getJobCode, setJobCode, setJobCodeMulti and setAccessGroupMulti to the UserSvc
- 0.2.0.1 - Added searchInfoToConnectInfo(self, searchInfo, isAsync) under ConnectSvc, allowing generation of Connection Parameters directly from search results
- 0.2.0.0 - Upgraded support for gRPC to the newest version supported by python (Regenerated .py files from .proto)
- 0.1.9.0 - Added zone services, LockZone, APBZone, TimedAPBZone, FireZone, InterlockZone and IntrusionZone are included. Also edited protobuf version to include security fixes (3.20.1)
- 0.1.8.8 - Fixed minor issue with finger.scan (Did not return data)
- 0.1.8.6 - Fixed minor issues
- 0.1.8 - Implemented version check for Protobuf (3.20)
- 0.1.7 - Implemented proper logging, a GSDKlog.log file is now used instead of the standard print command.
- 0.1.6 - Added firmwareUpdateMulti to DeviceSvc (Needed for multiple device upgrade internally)
- 0.1.5 - Added OperatorSvc call so operators above 10 can be added. Supports getList, add, delete, deleteAll, addMulti, deleteMulti and deleteAllMulti
- 0.1.4 - Added getFinger, getFace and getCard to UserSvc. Added getQRConfig, setQRConfig and writeQR to CardSvc()
- 0.1.3 - Added AuthSvc, AccessSvc, ScheduleSvc, ActionSvc and TNASvc.
        Under UserSvc, added newUser, newUserCard, newUserFinger and newUserFace for ease of calling when enrolling new user info.
- 0.1.2 - Updated initial json file string, so import on linux works
- 0.1.1 - Added Readme
- 0.1.0 - Initial Commit

