Skip to main content

No project description provided

Project description

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.

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

Features

  • Authenticate with Unifi Access using admin credentials.
  • Retrieve, create, activate, deactivate, and delete user accounts.
  • Update user group assignments.

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
unifiApi = UnipyAccess(
    base_url=os.getenv('UNIFI_CONTROLLER_ADDRESS'),
    username=os.getenv('UNIFI_LOGIN'),
    password=os.getenv('UNIFI_PASSWORD'),
    verify=os.getenv('VERIFY_SSL')
)

# Example: Create a new user
users = [
    {
        "first_name": "John",
        "last_name": "Doe",
        "PersonId": 124,
        "group_ids": ["bc1bf76d-5d2a-4a90-ae50-6aca02bccc63"]
    }
]
unifiApi.create_unifi_users(users)

Methods

1. get_unifi_users()

Fetches the list of users from Unifi Access.

Usage:

users = unifiApi.get_unifi_users()
print(users)

2. create_unifi_users(users)

Creates new users.

Parameters:

  • users (list): List of user dictionaries containing:
    • 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:

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

3. deactivate_unifi_users(users)

Deactivates users.

Usage:

users = [{"id": "user-123"}]
unifiApi.deactivate_unifi_users(users)

4. activate_unifi_users(users)

Activates users.

Usage:

users = [{"id": "user-123"}]
unifiApi.activate_unifi_users(users)

5. delete_unifi_users(users)

Deletes users.

Usage:

users = [{"id": "user-123"}]
unifiApi.delete_unifi_users(users)

6. set_users_group(users)

Updates user group assignments.

Usage:

users = [{"id": "user-123", "group": "group-456"}]
unifiApi.set_users_group(users)

Example Code

from unipyaccess import UnipyAccess
from dotenv import load_dotenv
import os

load_dotenv()

unifiApi = 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
print(unifiApi.get_unifi_users())

# Create a user
new_user = [{"first_name": "Alice", "last_name": "Smith", "PersonId": "125"}]
unifiApi.create_unifi_users(new_user)

# Activate a user
unifiApi.activate_unifi_users([{"id": "user-123"}])

# Deactivate a user
unifiApi.deactivate_unifi_users([{"id": "user-123"}])

# Delete a user
unifiApi.delete_unifi_users([{"id": "user-123"}])

# Update user group
unifiApi.set_users_group([{"id": "user-123", "group": "group-789"}])

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.1.0.tar.gz (4.4 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.1.0-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: unipyaccess-0.1.0.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for unipyaccess-0.1.0.tar.gz
Algorithm Hash digest
SHA256 42494dddb073b85961dcadd9d3caccca67a27649a5894de1df1df7fcb0348261
MD5 57ebca61ea9f5118d12fc8485c1eac4d
BLAKE2b-256 9ef8bcb8f8eea0c2049cc018e6fa148345ff2c08f39cd11ff5ba35fadfe08e6b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: unipyAccess-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for unipyAccess-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e611469b321236a220d520ca465082fe88653ea6103de464dbaa7fff2be413a2
MD5 d6ab14d0cba46c32e334106f0fd47d72
BLAKE2b-256 feab307e437c40cdf5578c7621e2f91dd8f49f745f83bb1786766869b30703e3

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