slipperpy


Nameslipperpy JSON
Version 0.1.0 PyPI version JSON
download
home_pageNone
SummaryA Python GraphQL client library for Slipper Energy Management
upload_time2025-09-03 01:49:32
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseNone
keywords client electricity energy graphql slipper
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # SlipperPy

A Python GraphQL client library for Slipper Energy Management systems.

## Features

- πŸš€ Async/await support with `httpx`
- πŸ”’ Type-safe with Pydantic models
- πŸ“ Full GraphQL query and mutation support
- πŸ”„ WebSocket subscription support (planned)
- πŸ§ͺ Comprehensive test coverage
- πŸ“š Well-documented API
- ⚑ Energy consumption tracking
- πŸ’° Electricity price monitoring
- 🏠 Home management
- πŸ“± Device management

## Installation

```bash
pip install slipperpy
```

For development dependencies:

```bash
pip install slipperpy[dev]
```

## Quick Start

```python
import asyncio
from slipperpy import SlipperClient

async def main():
    client = SlipperClient("https://api.slipper.no/graphql")
    
    # Step 1: Request SMS verification code
    success = await client.request_sms_code("+47123456789")
    if success:
        print("SMS code sent!")
        
        # Step 2: Get the SMS code from user input
        sms_code = input("Enter SMS code: ")
        
        # Step 3: Login with SMS code
        token = await client.login_with_sms_code("+47123456789", int(sms_code))
        print(f"Logged in successfully!")
    
    # Get current user
    user = await client.get_current_user()
    print(f"Welcome, {user.first_name}!")
    
    # Get all homes
    homes = await client.get_homes()
    for home in homes:
        print(f"Home: {home.name} at {home.street} {home.street_number}")
    
    # Get consumption data for the first home
    if homes:
        from datetime import datetime, timedelta
        end_date = datetime.now()
        start_date = end_date - timedelta(days=7)
        
        consumptions = await client.get_consumptions(
            home_id=homes[0].id,
            start=start_date,
            end=end_date,
            granularity="DAY"
        )
        
        for consumption in consumptions:
            print(f"Date: {consumption.date}, kWh: {consumption.kwh}, Cost: {consumption.cost}")

if __name__ == "__main__":
    asyncio.run(main())
```

## Advanced Usage

### Authentication

#### SMS Login (Primary Method)
```python
client = SlipperClient("https://api.slipper.no/graphql")

# Step 1: Request SMS code
success = await client.request_sms_code("+47123456789")
if success:
    print("SMS code sent to your phone")

# Step 2: Enter the code you received via SMS
sms_code = input("Enter SMS code: ")

# Step 3: Complete login
token = await client.login_with_sms_code("+47123456789", int(sms_code))
print("Logged in successfully!")
```

#### Alternative: Combined SMS Method
```python
# Request SMS code
result = await client.login_with_sms("+47123456789")
print(result["message"])  # "SMS code requested"

# Login with SMS code (after receiving it)
result = await client.login_with_sms("+47123456789", code=123456)
if result["success"]:
    print("Logged in!")
```

#### Phone and Password Login (if available)
```python
# Only use if your account supports password login
token = await client.login_with_phone_and_password("+47123456789", "password")
```

#### Using Existing Token
```python
client = SlipperClient("https://api.slipper.no/graphql")
client.set_auth_token("your-existing-jwt-token")
```

### Home Management

```python
# Get all homes
homes = await client.get_homes()

# Get a specific home
home = await client.get_home("home-id")

# Get archived homes
archived_homes = await client.get_homes(archived=True)
```

### Energy Consumption

```python
from datetime import datetime, timedelta

# Get consumption for the last month
end_date = datetime.now()
start_date = end_date - timedelta(days=30)

consumptions = await client.get_consumptions(
    home_id="your-home-id",
    start=start_date,
    end=end_date,
    granularity="DAY"  # Options: HOUR, DAY, MONTH
)

for consumption in consumptions:
    print(f"Date: {consumption.date}")
    print(f"Consumption: {consumption.kwh} kWh")
    print(f"Cost: {consumption.cost} NOK")
    print(f"Tax: {consumption.tax} NOK")
    print("---")
```

### Electricity Prices

```python
from datetime import datetime, timedelta

# Get electricity prices for tomorrow
start_date = datetime.now() + timedelta(days=1)
end_date = start_date + timedelta(days=1)

prices = await client.get_electricity_prices(
    start=start_date,
    end=end_date,
    granularity="HOUR",
    area="NO1",  # Norwegian price area
    forecast=True
)

for price in prices:
    print(f"Time: {price.date}, Price: {price.price} ΓΈre/kWh")
```

### Plan Management

```python
# Get all available electricity plans
plans = await client.get_plans()

# Get plans from a specific provider
plans = await client.get_plans(provider_id="provider-id")

# Get only active plans
active_plans = await client.get_plans(active=True)

for plan in plans:
    print(f"Plan: {plan.name}")
    print(f"Provider: {plan.provider}")
    print(f"Price per kWh: {plan.price_per_kwh}")
    print(f"Fixed fee: {plan.fixed_fee}")
```

### Provider Information

```python
# Get all electricity providers
providers = await client.get_providers()

for provider in providers:
    print(f"Provider: {provider.name}")
    print(f"Website: {provider.website}")
    print(f"Phone: {provider.phone}")
```

### User Management

```python
# Get current user information
user = await client.get_current_user()
print(f"User: {user.first_name} {user.last_name}")
print(f"Email: {user.email}")

# Update user information
success = await client.update_user(
    first_name="New Name",
    email="new.email@example.com"
)
```

### Raw GraphQL Queries

```python
# Execute custom GraphQL queries
query = """
query CustomQuery($homeId: ID!) {
    home(id: $homeId) {
        id
        name
        estimatedYearlyConsumption
        currentPlan {
            name
            pricePerKwh
        }
    }
}
"""

result = await client.execute(query, {"homeId": "your-home-id"})
print(result.data)
```

### Error Handling

```python
from slipperpy.exceptions import GraphQLError, NetworkError, AuthenticationError

try:
    homes = await client.get_homes()
except AuthenticationError:
    print("Authentication failed - please log in")
except NetworkError as e:
    print(f"Network error: {e.message}")
except GraphQLError as e:
    print(f"GraphQL error: {e.message}")
```

### Context Manager

```python
async with SlipperClient("https://api.slipper.no/graphql") as client:
    await client.login_with_phone("+47123456789", "password")
    homes = await client.get_homes()
    # Client is automatically closed when exiting the context
```

## Data Models

The library provides typed Pydantic models for all GraphQL types:

- `HomeType` - Represents a home/property
- `UserType` - Represents a user account
- `ConsumptionType` - Energy consumption data
- `ElectricityPriceType` - Electricity price information
- `PlanType` - Electricity plans/tariffs
- `ProviderType` - Electricity providers
- `DeviceType` - User devices (mobile, web, etc.)
- And many more...

## Development

### Setup

```bash
git clone https://github.com/yourusername/slipperpy.git
cd slipperpy
pip install -e .[dev]
```

### Running Tests

```bash
pytest
```

### Code Formatting

```bash
black src tests
isort src tests
```

### Type Checking

```bash
mypy src/slipperpy
```

## License

MIT License - see LICENSE file for details.

## Contributing

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

## API Documentation

For complete API documentation, see the [GraphQL schema](src/graphql/schema.graphql) or explore the typed models in the source code.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "slipperpy",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "client, electricity, energy, graphql, slipper",
    "author": null,
    "author_email": "Your Name <your.email@example.com>",
    "download_url": "https://files.pythonhosted.org/packages/0d/44/e14b088af222ea2a7d415fce84e668edb53badfd39373d79467b7f3fcb6a/slipperpy-0.1.0.tar.gz",
    "platform": null,
    "description": "# SlipperPy\n\nA Python GraphQL client library for Slipper Energy Management systems.\n\n## Features\n\n- \ud83d\ude80 Async/await support with `httpx`\n- \ud83d\udd12 Type-safe with Pydantic models\n- \ud83d\udcdd Full GraphQL query and mutation support\n- \ud83d\udd04 WebSocket subscription support (planned)\n- \ud83e\uddea Comprehensive test coverage\n- \ud83d\udcda Well-documented API\n- \u26a1 Energy consumption tracking\n- \ud83d\udcb0 Electricity price monitoring\n- \ud83c\udfe0 Home management\n- \ud83d\udcf1 Device management\n\n## Installation\n\n```bash\npip install slipperpy\n```\n\nFor development dependencies:\n\n```bash\npip install slipperpy[dev]\n```\n\n## Quick Start\n\n```python\nimport asyncio\nfrom slipperpy import SlipperClient\n\nasync def main():\n    client = SlipperClient(\"https://api.slipper.no/graphql\")\n    \n    # Step 1: Request SMS verification code\n    success = await client.request_sms_code(\"+47123456789\")\n    if success:\n        print(\"SMS code sent!\")\n        \n        # Step 2: Get the SMS code from user input\n        sms_code = input(\"Enter SMS code: \")\n        \n        # Step 3: Login with SMS code\n        token = await client.login_with_sms_code(\"+47123456789\", int(sms_code))\n        print(f\"Logged in successfully!\")\n    \n    # Get current user\n    user = await client.get_current_user()\n    print(f\"Welcome, {user.first_name}!\")\n    \n    # Get all homes\n    homes = await client.get_homes()\n    for home in homes:\n        print(f\"Home: {home.name} at {home.street} {home.street_number}\")\n    \n    # Get consumption data for the first home\n    if homes:\n        from datetime import datetime, timedelta\n        end_date = datetime.now()\n        start_date = end_date - timedelta(days=7)\n        \n        consumptions = await client.get_consumptions(\n            home_id=homes[0].id,\n            start=start_date,\n            end=end_date,\n            granularity=\"DAY\"\n        )\n        \n        for consumption in consumptions:\n            print(f\"Date: {consumption.date}, kWh: {consumption.kwh}, Cost: {consumption.cost}\")\n\nif __name__ == \"__main__\":\n    asyncio.run(main())\n```\n\n## Advanced Usage\n\n### Authentication\n\n#### SMS Login (Primary Method)\n```python\nclient = SlipperClient(\"https://api.slipper.no/graphql\")\n\n# Step 1: Request SMS code\nsuccess = await client.request_sms_code(\"+47123456789\")\nif success:\n    print(\"SMS code sent to your phone\")\n\n# Step 2: Enter the code you received via SMS\nsms_code = input(\"Enter SMS code: \")\n\n# Step 3: Complete login\ntoken = await client.login_with_sms_code(\"+47123456789\", int(sms_code))\nprint(\"Logged in successfully!\")\n```\n\n#### Alternative: Combined SMS Method\n```python\n# Request SMS code\nresult = await client.login_with_sms(\"+47123456789\")\nprint(result[\"message\"])  # \"SMS code requested\"\n\n# Login with SMS code (after receiving it)\nresult = await client.login_with_sms(\"+47123456789\", code=123456)\nif result[\"success\"]:\n    print(\"Logged in!\")\n```\n\n#### Phone and Password Login (if available)\n```python\n# Only use if your account supports password login\ntoken = await client.login_with_phone_and_password(\"+47123456789\", \"password\")\n```\n\n#### Using Existing Token\n```python\nclient = SlipperClient(\"https://api.slipper.no/graphql\")\nclient.set_auth_token(\"your-existing-jwt-token\")\n```\n\n### Home Management\n\n```python\n# Get all homes\nhomes = await client.get_homes()\n\n# Get a specific home\nhome = await client.get_home(\"home-id\")\n\n# Get archived homes\narchived_homes = await client.get_homes(archived=True)\n```\n\n### Energy Consumption\n\n```python\nfrom datetime import datetime, timedelta\n\n# Get consumption for the last month\nend_date = datetime.now()\nstart_date = end_date - timedelta(days=30)\n\nconsumptions = await client.get_consumptions(\n    home_id=\"your-home-id\",\n    start=start_date,\n    end=end_date,\n    granularity=\"DAY\"  # Options: HOUR, DAY, MONTH\n)\n\nfor consumption in consumptions:\n    print(f\"Date: {consumption.date}\")\n    print(f\"Consumption: {consumption.kwh} kWh\")\n    print(f\"Cost: {consumption.cost} NOK\")\n    print(f\"Tax: {consumption.tax} NOK\")\n    print(\"---\")\n```\n\n### Electricity Prices\n\n```python\nfrom datetime import datetime, timedelta\n\n# Get electricity prices for tomorrow\nstart_date = datetime.now() + timedelta(days=1)\nend_date = start_date + timedelta(days=1)\n\nprices = await client.get_electricity_prices(\n    start=start_date,\n    end=end_date,\n    granularity=\"HOUR\",\n    area=\"NO1\",  # Norwegian price area\n    forecast=True\n)\n\nfor price in prices:\n    print(f\"Time: {price.date}, Price: {price.price} \u00f8re/kWh\")\n```\n\n### Plan Management\n\n```python\n# Get all available electricity plans\nplans = await client.get_plans()\n\n# Get plans from a specific provider\nplans = await client.get_plans(provider_id=\"provider-id\")\n\n# Get only active plans\nactive_plans = await client.get_plans(active=True)\n\nfor plan in plans:\n    print(f\"Plan: {plan.name}\")\n    print(f\"Provider: {plan.provider}\")\n    print(f\"Price per kWh: {plan.price_per_kwh}\")\n    print(f\"Fixed fee: {plan.fixed_fee}\")\n```\n\n### Provider Information\n\n```python\n# Get all electricity providers\nproviders = await client.get_providers()\n\nfor provider in providers:\n    print(f\"Provider: {provider.name}\")\n    print(f\"Website: {provider.website}\")\n    print(f\"Phone: {provider.phone}\")\n```\n\n### User Management\n\n```python\n# Get current user information\nuser = await client.get_current_user()\nprint(f\"User: {user.first_name} {user.last_name}\")\nprint(f\"Email: {user.email}\")\n\n# Update user information\nsuccess = await client.update_user(\n    first_name=\"New Name\",\n    email=\"new.email@example.com\"\n)\n```\n\n### Raw GraphQL Queries\n\n```python\n# Execute custom GraphQL queries\nquery = \"\"\"\nquery CustomQuery($homeId: ID!) {\n    home(id: $homeId) {\n        id\n        name\n        estimatedYearlyConsumption\n        currentPlan {\n            name\n            pricePerKwh\n        }\n    }\n}\n\"\"\"\n\nresult = await client.execute(query, {\"homeId\": \"your-home-id\"})\nprint(result.data)\n```\n\n### Error Handling\n\n```python\nfrom slipperpy.exceptions import GraphQLError, NetworkError, AuthenticationError\n\ntry:\n    homes = await client.get_homes()\nexcept AuthenticationError:\n    print(\"Authentication failed - please log in\")\nexcept NetworkError as e:\n    print(f\"Network error: {e.message}\")\nexcept GraphQLError as e:\n    print(f\"GraphQL error: {e.message}\")\n```\n\n### Context Manager\n\n```python\nasync with SlipperClient(\"https://api.slipper.no/graphql\") as client:\n    await client.login_with_phone(\"+47123456789\", \"password\")\n    homes = await client.get_homes()\n    # Client is automatically closed when exiting the context\n```\n\n## Data Models\n\nThe library provides typed Pydantic models for all GraphQL types:\n\n- `HomeType` - Represents a home/property\n- `UserType` - Represents a user account\n- `ConsumptionType` - Energy consumption data\n- `ElectricityPriceType` - Electricity price information\n- `PlanType` - Electricity plans/tariffs\n- `ProviderType` - Electricity providers\n- `DeviceType` - User devices (mobile, web, etc.)\n- And many more...\n\n## Development\n\n### Setup\n\n```bash\ngit clone https://github.com/yourusername/slipperpy.git\ncd slipperpy\npip install -e .[dev]\n```\n\n### Running Tests\n\n```bash\npytest\n```\n\n### Code Formatting\n\n```bash\nblack src tests\nisort src tests\n```\n\n### Type Checking\n\n```bash\nmypy src/slipperpy\n```\n\n## License\n\nMIT License - see LICENSE file for details.\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n## API Documentation\n\nFor complete API documentation, see the [GraphQL schema](src/graphql/schema.graphql) or explore the typed models in the source code.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A Python GraphQL client library for Slipper Energy Management",
    "version": "0.1.0",
    "project_urls": {
        "Documentation": "https://github.com/yourusername/slipperpy#readme",
        "Issues": "https://github.com/yourusername/slipperpy/issues",
        "Source": "https://github.com/yourusername/slipperpy"
    },
    "split_keywords": [
        "client",
        " electricity",
        " energy",
        " graphql",
        " slipper"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "8e27e7f2e20f277ba0f9c4d078e5d7f1a0d1b3b0e25f9f0452df1d4f32b00cb9",
                "md5": "ad351a427bd364898e6e72a93f2a03c1",
                "sha256": "d718c79a1a5f9a9b0dc9eff4064fdecd9ed15fddb75bccd1586be1a24915ec5a"
            },
            "downloads": -1,
            "filename": "slipperpy-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ad351a427bd364898e6e72a93f2a03c1",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 16908,
            "upload_time": "2025-09-03T01:49:31",
            "upload_time_iso_8601": "2025-09-03T01:49:31.276674Z",
            "url": "https://files.pythonhosted.org/packages/8e/27/e7f2e20f277ba0f9c4d078e5d7f1a0d1b3b0e25f9f0452df1d4f32b00cb9/slipperpy-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "0d44e14b088af222ea2a7d415fce84e668edb53badfd39373d79467b7f3fcb6a",
                "md5": "0a69bb83350e89392bb67c84727b481f",
                "sha256": "ede4e3ba46f5edf28d30f444186c47b2b4d51105162a88cc76cd9d3647f5a7bf"
            },
            "downloads": -1,
            "filename": "slipperpy-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "0a69bb83350e89392bb67c84727b481f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 27476,
            "upload_time": "2025-09-03T01:49:32",
            "upload_time_iso_8601": "2025-09-03T01:49:32.815654Z",
            "url": "https://files.pythonhosted.org/packages/0d/44/e14b088af222ea2a7d415fce84e668edb53badfd39373d79467b7f3fcb6a/slipperpy-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-09-03 01:49:32",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "yourusername",
    "github_project": "slipperpy#readme",
    "github_not_found": true,
    "lcname": "slipperpy"
}
        
Elapsed time: 4.05696s