Skip to main content

No project description provided

Project description

licence issues deploy tag

unipyaccess

unipyaccess is a Python package designed to interface with the Unifi Access system. This package provides a simple and efficient way to manage users in Unifi Access, including authentication, retrieval, creation, activation, deactivation, deletion, and updating of user groups and hardware settings.

[!NOTE]
This implementation uses Unifi API endpoints with admin user authentication. It does not utilize the latest, in my opinion half-baked Unifi API.

[!WARNING]
🚧 This project is under active development, and breaking changes are expected in upcoming releases.

Features

  • Authenticate with Unifi Access using admin credentials.
  • Retrieve, create, activate, deactivate, and delete user accounts.
  • Update user group assignments.
  • Manage Unifi Access hardware, including access methods, display brightness, and device status.

Installation

Install the package via pip:

pip install unipyaccess

Requirements

  • Python 3.x
  • requests library

Install the requirements with:

pip install requests

Environment Setup

Store your configuration details in a .env file:

UNIFI_CONTROLLER_ADDRESS=https://unifi-controller.local
UNIFI_LOGIN=admin
UNIFI_PASSWORD=password123
VERIFY_SSL=False

Usage

Import unipyaccess and use it in your Python script:

from unipyaccess import UnipyAccess
from dotenv import load_dotenv
import os

load_dotenv()

# Initialize the UnipyAccess API client
unipy = UnipyAccess(
    base_url=os.getenv('UNIFI_CONTROLLER_ADDRESS'),
    username=os.getenv('UNIFI_LOGIN'),
    password=os.getenv('UNIFI_PASSWORD'),
    verify=os.getenv('VERIFY_SSL')
)

# Features
users = unipy.users.get_users()

new_user = {
    "first_name": "Python",
    "last_name": "Test",
    "PersonId": 98765,
}

unipy.users.create_user(new_user)
unipy.users.deactivate_user(uuid)
unipy.users.activate_user(uuid)
unipy.users.set_user_group(uuid, group_uuid)
unipy.users.delete_user(uuid)

# Hardware management
devices = unipy.hardware.get_devices()

unipy.hardware.get_device(device_id)
unipy.hardware.set_access_method(device_id, ["pin", "nfc", "mobile_tap", "mobile_button"])
unipy.hardware.set_doorbell_trigger(device_id, "tap")
unipy.hardware.set_status_light(device_id, "on")
unipy.hardware.set_display_brightness(device_id, 50)
unipy.hardware.set_status_sound("f4e2c6d3085d", 30)  # For models other than UA G2 Pro use "on" or "off"
unipy.hardware.get_device_capabilities(device_id)
unipy.hardware.get_device_model(device_id)
unipy.hardware.restart_device(device_id)

Methods

User Management

1. unipy.users.create_user(new_user)

Creates a new user.

Parameters:

  • new_user (dict): Dictionary containing user details:
    • first_name (str): User's first name.
    • last_name (str): User's last name.
    • PersonId (str): Optional employee number.
    • group_ids (list): Optional list of group IDs.

Usage:

new_user = {
    "first_name": "Jane",
    "last_name": "Doe",
    "PersonId": "789",
    "group_ids": ["group-123"]
}
unipy.users.create_user(new_user)

2. unipy.users.deactivate_user(uuid)

Deactivates a user.

Parameters:

  • uuid (str): User’s unique identifier.

Usage:

unipy.users.deactivate_user("user-123")

3. unipy.users.activate_user(uuid)

Activates a user.

Parameters:

  • uuid (str): User’s unique identifier.

Usage:

unipy.users.activate_user("user-123")

4. unipy.users.set_user_group(uuid, group_uuid)

Updates the user group assignment.

Parameters:

  • uuid (str): User’s unique identifier.
  • group_uuid (str): Group’s unique identifier.

Usage:

unipy.users.set_user_group("user-123", "group-789")

5. unipy.users.delete_user(uuid)

Deletes a user.

Parameters:

  • uuid (str): User’s unique identifier.

Usage:

unipy.users.delete_user("user-123")

Hardware Management

1. unipy.hardware.get_devices()

Fetches a list of hardware devices.

Usage:

devices = unipy.hardware.get_devices()

2. unipy.hardware.get_device(device_id)

Fetches details of a specific device.

Usage:

device = unipy.hardware.get_device("device-123")

3. unipy.hardware.set_access_method(device_id, enabled_methods)

Sets the access methods for a device.

Usage:

unipy.hardware.set_access_method("device-123", ["pin", "nfc"])

4. unipy.hardware.set_doorbell_trigger(device_id, doorbell_trigger)

Sets the doorbell trigger type for a device.

Usage:

unipy.hardware.set_doorbell_trigger("device-123", "tap")

5. unipy.hardware.set_status_light(device_id, status_light)

Sets the status light for a device.

Usage:

unipy.hardware.set_status_light("device-123", "on")

6. unipy.hardware.set_display_brightness(device_id, brightness)

Sets the display brightness for a device.

Usage:

unipy.hardware.set_display_brightness("device-123", 50)

7. unipy.hardware.set_status_sound(device_id, status_sound)

Sets the status sound for a device.

Usage:

unipy.hardware.set_status_sound("device-123", 30)

8. unipy.hardware.get_device_capabilities(device_id)

Fetches the capabilities of a device.

Usage:

capabilities = unipy.hardware.get_device_capabilities("device-123")

9. unipy.hardware.get_device_model(device_id)

Fetches the model of a device.

Usage:

model = unipy.hardware.get_device_model("device-123")

10. unipy.hardware.restart_device(device_id)

Restarts a device.

Usage:

unipy.hardware.restart_device("device-123")

Example Code

from unipyaccess import UnipyAccess
from dotenv import load_dotenv
import os

load_dotenv()

unipy = UnipyAccess(
    base_url=os.getenv('UNIFI_CONTROLLER_ADDRESS'),
    username=os.getenv('UNIFI_LOGIN'),
    password=os.getenv('UNIFI_PASSWORD'),
    verify=os.getenv('VERIFY_SSL')
)

# Retrieve users
users = unipy.users.get_users()
print(users)

# Create a user
new_user = {
    "first_name": "Alice",
    "last_name": "Smith",
    "PersonId": "125"
}
unipy.users.create_user(new_user)

# Activate a user
unipy.users.activate_user("user-123")

# Deactivate a user
unipy.users.deactivate_user("user-123")

# Delete a user
unipy.users.delete_user("user-123")

# Update user group
unipy.users.set_user_group("user-123", "group-789")

# Hardware Management
# Get devices
devices = unipy.hardware.get_devices()
print(devices)

# Set device configurations
unipy.hardware.set_access_method("device-123", ["pin", "nfc"])
unipy.hardware.set_display_brightness("device-123", 50)
unipy.hardware.set_status_sound("device-123", "on")

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

unipyaccess-0.2.0.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

unipyAccess-0.2.0-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file unipyaccess-0.2.0.tar.gz.

File metadata

  • Download URL: unipyaccess-0.2.0.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for unipyaccess-0.2.0.tar.gz
Algorithm Hash digest
SHA256 74ab945282f6fdb63db76b61f5cf68a1fc411b10bea7dad0e7c269955927eb78
MD5 ea5e29d54a2e189e97753aac31b666a0
BLAKE2b-256 f8e0a6c36e19315c8130a8b0f9f1fa93b2d995edd9b7fe133eb8051cfed7f628

See more details on using hashes here.

File details

Details for the file unipyAccess-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: unipyAccess-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for unipyAccess-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ad1c52e2c8c1953c02fcab1c91624a20632d852b0ea33de579fd861af5f571ce
MD5 f378fa3537a8cc477b743b9886eb9a73
BLAKE2b-256 9452f83cb6abcc584a84a518f0c42c2b72fbc21444db762bc613b7cf4d123de9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page