A professional-grade Python library for controlling Digital Loggers Power Switch Pro devices via their REST API.
Designed for: Firmware version 1.7.0+ with REST API support (API specification 20221009T204818Z)
Disclaimer: This is an unofficial library that was reverse-engineered from Digital Loggers' official REST API documentation. It is not affiliated with, endorsed by, or supported by Digital Loggers. Use at your own risk.
- π Full REST API Support - Complete implementation of DLI REST-style API
- β‘ Outlet Control - Turn outlets on/off/cycle individually or in bulk
- π Power Monitoring - Real-time voltage, current, power, and energy measurements*
- π₯ User Management - Create, modify, and manage device users
- π§ Device Configuration - Access and modify device settings
- π AutoPing - Configure automatic host monitoring and recovery
- π Script Execution - Run custom scripts on the device
* Power Monitoring Note: The power metering APIs (get_voltage(), get_current(), get_power()) are implemented based on the official API specification but remain untested. The test device does not have power monitoring hardware installed. These methods will work on devices with power metering capabilities but will return a clear error message on devices without this hardware.
- π Pythonic API - Intuitive interface with properties and array indexing
- π Secure - HTTP Digest Authentication and CSRF protection
- π HTTPS Support - Optional SSL/TLS encryption
- π Type Hints - Full type annotations for better IDE support
- π§ͺ Well Tested - Comprehensive test suite with >80% coverage
- π Documented - Extensive documentation with examples
pip install power_switch_profrom power_switch_pro import PowerSwitchPro
# Connect to device
switch = PowerSwitchPro("192.168.0.100", "admin", "1234")
# Turn on outlet 1
switch.outlets[0].on()
# Turn off outlet 2
switch.outlets[1].off()
# Cycle outlet 3
switch.outlets[2].cycle()
# Get outlet state
state = switch.outlets[0].state
print(f"Outlet 1 is {'ON' if state else 'OFF'}")
# Get all outlet states
states = switch.outlets.get_all_states()
print(states)
# Get power metrics
voltage = switch.meters.get_voltage()
current = switch.meters.get_current()
print(f"Voltage: {voltage}V, Current: {current}A")# Turn off all unlocked outlets
switch.outlets.bulk_operation(locked=False, action='off')
# Get states of specific outlets
states = switch.outlets.get_states([0, 1, 4]) # Outlets 1, 2, and 5# Add a new user
switch.auth.add_user(
name="operator",
password="secret123",
outlet_access=[True, True, False, False, False, False, False, False]
)
# List all users
users = switch.auth.list_users()
# Delete a user
switch.auth.delete_user("operator")# Add AutoPing entry
switch.autoping.add_entry(
host="192.168.0.50",
outlet=0,
enabled=True
)# Get device configuration
config = switch.config.get_all()
# Update timezone
switch.config.set_timezone("UTC-5")
# Get device info
info = switch.info
print(f"Serial: {info['serial']}, Version: {info['version']}")Main class for interacting with the device.
Parameters:
host(str): Device IP address or hostnameusername(str): Admin usernamepassword(str): Admin passworduse_https(bool): Use HTTPS instead of HTTP (default: False)verify_ssl(bool): Verify SSL certificates (default: True)
Properties:
outlets: OutletManager for controlling outletsauth: AuthManager for user managementconfig: ConfigManager for device configurationmeters: MeterManager for power metricsautoping: AutoPingManager for AutoPing settingsscript: ScriptManager for script execution
Manage power outlets.
Methods:
on(outlet_id): Turn on an outletoff(outlet_id): Turn off an outletcycle(outlet_id): Cycle an outletget_state(outlet_id): Get outlet stateget_all_states(): Get all outlet statesget_name(outlet_id): Get outlet nameset_name(outlet_id, name): Set outlet namebulk_operation(**filters, action): Perform bulk operations
- Python 3.7+
- requests >= 2.25.0
BSD 3-Clause License. See LICENSE file for details.
Bryan Kemp (bryan@kempville.com)
Full documentation is available at power-switch-pro.readthedocs.io
- Installation Guide
- Device Information - Hardware specs and firmware compatibility
- Quick Start Guide
- API Reference
- Code Examples
- Contributing Guidelines
This library works with Digital Loggers power management devices that support the REST API:
- Web Power Switch Pro (LPC series)
- Pro Switch series
- Ethernet Power Controller III and later models
Minimum Firmware: 1.7.0 (REST API support required)
- Data Center Management: Remotely control and monitor rack-mounted equipment
- Lab Automation: Automate test equipment power cycling
- Server Management: Implement automated recovery for unresponsive servers
- IoT Projects: Integrate power control into home automation systems
- CI/CD Pipelines: Reset test hardware between test runs
- Energy Monitoring: Track power consumption of connected devices
- HTTP Digest Authentication - More secure than Basic auth (default)
- HTTPS/TLS Support - Encrypted communication
- CSRF Protection - Built-in protection against cross-site request forgery
- Session Management - Efficient connection reuse
- Per-Outlet Permissions - Granular access control for users
If you encounter an error like HTTPException('got more than 100 headers') when accessing device.info, this has been fixed in recent versions. Update to the latest version:
pip install --upgrade power_switch_proThis issue occurs with some Power Switch Pro devices that return excessive headers in their configuration endpoint responses. The library now automatically increases the header limit to accommodate these devices.
- Ensure you're using the correct admin password for your device
- The default password is device-specific (check your device documentation)
- Some devices use HTTP Digest authentication which requires exact password match (case-sensitive)
- If you experience repeated authentication failures, check for security lockout settings on the device
If you get an error saying "Power metering not available on this device", this means your Power Switch Pro model does not include power monitoring hardware. This is normal for some models. The power metering APIs are implemented according to the official specification but are untested as the development device lacks this hardware. If you have a device with power metering and encounter issues, please open an issue on GitHub.
# Install dev dependencies
pip install -e ".[dev]"
# Run tests
pytest
# Run tests with coverage
pytest --cov=power_switch_pro --cov-report=html
# Run linting
ruff check power_switch_pro tests
black --check power_switch_pro tests
# Run type checking
mypy power_switch_proThis project uses:
- Black for code formatting
- Ruff for fast Python linting
- mypy for static type checking
- pytest for testing
- Sphinx for documentation
See WARP.md for detailed development guidelines.
- β Production Ready - v1.0.0 released
- β Stable API - Production/Stable status
- β Well Tested - Comprehensive test coverage
- β Documented - Full documentation available
- β Type Safe - Complete type annotations
- β CI/CD - Automated testing and publishing
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Run tests and linting (
make test lint) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Please read CONTRIBUTING.md for detailed guidelines.
This project is licensed under the BSD 3-Clause License - see the LICENSE file for details.
- Digital Loggers for providing the REST API specification
- The Python community for excellent tools and libraries
- Documentation: https://power-switch-pro.readthedocs.io
- Issues: https://github.com/bryankemp/power_switch_pro/issues
- Email: bryan@kempville.com
Made with β€οΈ by Bryan Kemp