Python library for Digital Loggers Power Switch Pro REST API
Project description
Power Switch Pro Python Library
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)
✨ Features
Core Functionality
- 🔌 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
Python Features
- 🐍 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
Installation
pip install power_switch_pro
Quick Start
from 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")
Advanced Usage
Working with Multiple Outlets
# 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
User Management
# 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")
AutoPing Configuration
# Add AutoPing entry
switch.autoping.add_entry(
host="192.168.0.50",
outlet=0,
enabled=True
)
Configuration
# 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']}")
API Reference
PowerSwitchPro
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
OutletManager
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
Requirements
- Python 3.7+
- requests >= 2.25.0
License
BSD 3-Clause License. See LICENSE file for details.
Author
Bryan Kemp (bryan@kempville.com)
📖 Documentation
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
🚀 Supported Devices
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)
💡 Use Cases
- 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
🛡️ Security Features
- 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
🧪 Testing
# 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_pro
🔧 Development
This 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.
📊 Project Status
- ✅ Stable API - v0.1.0 released
- ✅ Well Tested - Comprehensive test coverage
- ✅ Documented - Full documentation available
- ✅ Type Safe - Complete type annotations
- ✅ CI/CD - Automated testing and publishing
🤝 Contributing
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.
📝 License
This project is licensed under the BSD 3-Clause License - see the LICENSE file for details.
🙏 Acknowledgments
- Digital Loggers for providing the REST API specification
- The Python community for excellent tools and libraries
📧 Support
- Documentation: https://power-switch-pro.readthedocs.io
- Issues: https://github.com/bryankemp/power_switch_pro/issues
- Email: bryan@kempville.com
🔗 Related Links
Made with ❤️ by Bryan Kemp
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file power_switch_pro-0.1.0.tar.gz.
File metadata
- Download URL: power_switch_pro-0.1.0.tar.gz
- Upload date:
- Size: 182.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
72728f163a159c53cd0e6956c9a2881a0f9af4689c7c35b7b84fce84d3c75b6a
|
|
| MD5 |
72568d7d3c2d7c916a535d03246fcbbd
|
|
| BLAKE2b-256 |
a561c1f3bfbf2e3c27614cea8ee99fcd49fd28a95ac165ce7cb5071c449ee45e
|
File details
Details for the file power_switch_pro-0.1.0-py3-none-any.whl.
File metadata
- Download URL: power_switch_pro-0.1.0-py3-none-any.whl
- Upload date:
- Size: 17.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
35169d0e493fa10716e6e1dac088eb4d5279740964790f467d3cbc2f7b568d6c
|
|
| MD5 |
23a9c657626981b43c6a8fe2e532152a
|
|
| BLAKE2b-256 |
b303f7472277de4618b03642bea22da6df7045bf16398bc651db45f9f10ceb61
|