Metadata-Version: 2.4
Name: redfish-python-sdk
Version: 1.0.0
Summary: A Python SDK for interacting with Redfish-compliant BMC endpoints
Author: RedNote Infrastructure
License: BSD 3-Clause License
        
        Copyright (c) 2025-present, Xingyin Information Technology Co., Ltd.
        All rights reserved.
        
        Redistribution and use in source and binary forms, with or without
        modification, are permitted provided that the following conditions are met:
        
        1. Redistributions of source code must retain the above copyright notice, this
           list of conditions and the following disclaimer.
        
        2. Redistributions in binary form must reproduce the above copyright notice,
           this list of conditions and the following disclaimer in the documentation
           and/or other materials provided with the distribution.
        
        3. Neither the name of the copyright holder nor the names of its
           contributors may be used to endorse or promote products derived from
           this software without specific prior written permission.
        
        THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
        AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
        DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
        FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
        DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
        SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
        CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
        OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
        OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
        
Project-URL: Homepage, https://github.com/rednote-infra/redfish-python-sdk
Project-URL: Repository, https://github.com/rednote-infra/redfish-python-sdk
Project-URL: Issues, https://github.com/rednote-infra/redfish-python-sdk/issues
Project-URL: Changelog, https://github.com/rednote-infra/redfish-python-sdk/blob/main/CHANGELOG.md
Keywords: redfish,bmc,ipmi,server,oob
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: System Administrators
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: BSD License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
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: Topic :: System :: Hardware
Classifier: Topic :: System :: Networking
Classifier: Topic :: System :: Systems Administration
Classifier: Typing :: Typed
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: requests>=2.31.0
Requires-Dist: pydantic>=2.5.0
Requires-Dist: urllib3>=2.0.0
Provides-Extra: dev
Requires-Dist: pytest>=7.0.0; extra == "dev"
Requires-Dist: ruff>=0.4.0; extra == "dev"
Dynamic: license-file

# Redfish Python SDK

[English](README.md) | [中文](README_zh.md)

> A lightweight Python SDK for managing server BMCs (Baseboard Management Controllers) via the [DMTF Redfish](https://www.dmtf.org/standards/redfish) protocol. Covers system inventory, hardware inspection, power control, boot management, event subscriptions, and more.

## Features

- **Comprehensive hardware queries** — CPU, memory, drives, GPU, NIC, PCIe, PSU, fans — one line of code each
- **Power & boot management** — power on/off, restart, PXE/HDD/BIOS boot source switching
- **Multi-vendor compatible** — auto-adapts to OEM extensions from Huawei, xFusion, Lenovo, HPE, Dell, and others
- **Pydantic v2 models** — all return values are strongly-typed objects with full IDE autocompletion
- **Context manager** — `with` statement support for automatic connection cleanup
- **Minimal dependencies** — only `requests`, `pydantic`, and `urllib3`

## Requirements

- Python >= 3.9
- A network-reachable Redfish-compliant BMC endpoint

## Installation

```bash
# Install from PyPI
pip install redfish-python-sdk

# Or install from GitHub
pip install git+https://github.com/rednote-infra/redfish-python-sdk.git

# Install a specific version
pip install redfish-python-sdk==1.0.0
pip install git+https://github.com/rednote-infra/redfish-python-sdk.git@v1.0.0

# In requirements.txt
# redfish-python-sdk>=1.0.0
```

## Quick Start

> **Credential management**: All BMC credentials should be injected via environment variables. **Never** hardcode them in your source code.
> Before running examples or tests, set `export BMC_IP=...`, `export BMC_USER=...`, `export BMC_PASSWORD=...`.

```python
import os
from redfish_sdk import RedfishClient

# Connect to BMC (credentials from environment variables)
client = RedfishClient(
    host=os.environ["BMC_IP"],
    username=os.environ["BMC_USER"],
    password=os.environ["BMC_PASSWORD"],
)

# Get system info
system = client.systems.get()
print(f"Server: {system.manufacturer} {system.model}")
print(f"SN:     {system.serial_number}")
print(f"Power:  {system.power_state}")

# Get CPU info
for cpu in client.get_processors():
    print(f"CPU: {cpu.model}, {cpu.total_cores} cores / {cpu.total_threads} threads")

# Get memory info
for mem in client.get_memory():
    print(f"DIMM: {mem.manufacturer} {(mem.capacity_mib or 0) // 1024} GB")

# Get drive info
for drive in client.get_drives():
    print(f"Drive: {drive.model} {(drive.capacity_bytes or 0) / 1e12:.1f} TB")

# Don't forget to close
client.close()
```

## Testing

```bash
# Run unit tests (no BMC or env vars required)
pytest tests/test_models_mock.py tests/test_client_mock.py -v

# Run offline tests (using pre-collected JSON data)
export REDFISH_JSON_DIR="./testdata"
pytest tests/test_offline_json.py -v

# Run integration tests (requires a real BMC)
export BMC_IP="<your-bmc-ip>"
export BMC_USER="<your-bmc-user>"
export BMC_PASSWORD="<your-bmc-password>"
pytest tests/test_real_bmc.py -v
```

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

## License

This project is licensed under the [BSD 3-Clause License](LICENSE).
