Skip to main content

Client for Creality Wifi Box

Project description

Creality WiFi Box Client

A Python async client library for interacting with the Creality WiFi Box API.

Installation

pip install creality-wifi-box-client

Features

  • ✨ Async/await support with proper resource management
  • 🔒 Type-safe with full type hints
  • 🛡️ Comprehensive error handling
  • ⚡ Efficient session reuse
  • 📦 Pydantic data validation
  • 🧪 100% test coverage

Quick Start

Basic Usage

import asyncio
from creality_wifi_box_client import CrealityWifiBoxClient

async def main() -> None:
    # Create client with context manager (recommended)
    async with CrealityWifiBoxClient("192.168.1.100", 8080) as client:
        # Get printer info
        info = await client.get_info()
        print(f"Printer Model: {info.model}")
        print(f"Print Progress: {info.print_progress}%")
        print(f"Nozzle Temperature: {info.nozzle_temp}°C")
        print(f"Bed Temperature: {info.bed_temp}°C")

        # Control print job
        await client.pause_print()
        await asyncio.sleep(5)
        await client.resume_print()

asyncio.run(main())

Manual Session Management

async def main() -> None:
    client = CrealityWifiBoxClient("192.168.1.100", 8080, timeout=30)

    try:
        info = await client.get_info()
        print(f"Current file: {info.print_name}")
    finally:
        await client.close()

API Reference

CrealityWifiBoxClient

Constructor

CrealityWifiBoxClient(box_ip: str, box_port: int, timeout: int = 30)

Parameters:

  • box_ip: IP address of the WiFi Box
  • box_port: Port number (typically 8080)
  • timeout: Request timeout in seconds (default: 30)

Methods

async get_info() -> BoxInfo

Retrieves comprehensive printer and box information.

Returns: BoxInfo object with all device data

Raises:

  • ClientConnectionError: Connection to box failed
  • RequestTimeoutError: Request timed out
  • InvalidResponseError: Malformed response
async pause_print() -> bool

Pauses the current print job.

Returns: True if successful

Raises:

  • ClientConnectionError: Connection failed
  • RequestTimeoutError: Request timed out
  • CommandError: Command failed on the box
async resume_print() -> bool

Resumes a paused print job.

Returns: True if successful

async stop_print() -> bool

Stops the current print job.

Returns: True if successful

async close() -> None

Closes the client session and cleans up resources. Called automatically when using context manager.

BoxInfo

The BoxInfo class contains all printer and box information with the following key fields:

Network:

  • wanip, ssid, net_ip

Temperatures:

  • nozzle_temp, bed_temp, chamber_temp

Print Status:

  • print_name, print_progress, state, pause
  • print_left_time, print_job_time
  • layer, total_layer

Device Info:

  • model, box_version, model_version
  • filament_type, consumables_len

Error Handling

The library provides specific exceptions for different error scenarios:

from creality_wifi_box_client import (
    CrealityWifiBoxClient,
    ClientConnectionError,
    RequestTimeoutError,
    CommandError,
    InvalidResponseError,
)

async def safe_print_control() -> None:
    async with CrealityWifiBoxClient("192.168.1.100", 8080) as client:
        try:
            await client.pause_print()
        except ClientConnectionError:
            print("Could not connect to printer")
        except RequestTimeoutError:
            print("Request timed out")
        except CommandError:
            print("Command failed on the printer")
        except InvalidResponseError:
            print("Received invalid response")

Development

Setup

# Clone repository
git clone https://github.com/pcartwright81/creality_wifi_box_client.git
cd creality_wifi_box_client

# Create virtual environment
python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate

# Install with dev dependencies
pip install -e .[dev,test]

Testing

# Run tests with coverage
pytest

# Run linting
ruff check .
ruff format . --check

License

MIT License - see LICENSE file for details.

Contributing

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

Credits

Created by Patrick Cartwright (@pcartwright81)

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

creality_wifi_box_client-0.1.0.tar.gz (11.3 kB view details)

Uploaded Source

Built Distribution

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

creality_wifi_box_client-0.1.0-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: creality_wifi_box_client-0.1.0.tar.gz
  • Upload date:
  • Size: 11.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.9

File hashes

Hashes for creality_wifi_box_client-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c0b481e3c0dca8e64208b2fc5746dddc34e78966642a9c413eb15faaeb57cdf7
MD5 026d8c245e02cecda65d90cac5dcf177
BLAKE2b-256 fac412735841e819b79228c81ca97e1cb79fc884b28a681807c0da5fb352a923

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for creality_wifi_box_client-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1161ad988c48ed9426e359194887699c610dbc9c0625152888166ba334d44a34
MD5 2bb397ec044e73819cde30f4dfc4d1d4
BLAKE2b-256 669668dd5bbc5df01a5d7a9749357608c225a0a0fb5fe2c66842f3076a26cd37

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