Metadata-Version: 2.4
Name: cereon_sdk
Version: 0.1.0
Summary: Generic, typed, and streaming FastAPI backend for Cereon Dashboard cards.
Project-URL: Homepage, https://github.com/adimis-ai/cereon
Project-URL: Repository, https://github.com/adimis-ai/cereon
Project-URL: Issues, https://github.com/adimis-ai/cereon/issues
Author-email: Aditya Mishra <adimis.sde@gmail.com>
License: MIT License
        
        Copyright (c) 2025 Cereon
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: dashboard,fastapi,ndjson,sse,streaming,typed-api,websocket
Classifier: Framework :: FastAPI
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.10
Requires-Dist: fastapi>=0.110.0
Requires-Dist: pydantic>=2.6.0
Requires-Dist: typing-extensions>=4.9.0
Provides-Extra: dev
Requires-Dist: black; extra == 'dev'
Requires-Dist: pytest; extra == 'dev'
Requires-Dist: pytest-asyncio; extra == 'dev'
Requires-Dist: ruff; extra == 'dev'
Description-Content-Type: text/markdown

# Cereon SDK

> ⚠️ CONSTRUCTION / BETA NOTICE: The official beta release of these packages is scheduled for 1st December 2025. Expect breaking changes until the beta is published. If you plan to depend on this library for production, please wait until the official beta.

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![Python](https://img.shields.io/badge/Python-3.11-blue.svg?logo=python&logoColor=white)](https://www.python.org/) [![FastAPI](https://img.shields.io/badge/FastAPI-Ready-009688.svg?logo=fastapi&logoColor=white)](https://fastapi.tiangolo.com/)

**Cereon SDK** is a high-performance, typed FastAPI framework for building real-time dashboard backends. Create interactive dashboard cards with support for HTTP, WebSocket, and Server-Sent Events (SSE) transport protocols.

## 🚀 Quick Start

### Installation

```bash
pip install cereon-sdk
```

### Basic Example

Create your first dashboard card in minutes:

```python
from fastapi import FastAPI
from cereon_sdk import BaseCard, ChartCardRecord

app = FastAPI()

class SalesCard(BaseCard[ChartCardRecord]):
    kind = "line"
    card_id = "sales_overview"
    report_id = "dashboard"
    route_prefix = "/api/cards"
    response_model = ChartCardRecord
    transport = "http"

    @classmethod
    async def handler(cls, ctx):
        # Your data logic here
        data = [
            {"date": "2024-01-01", "sales": 1200},
            {"date": "2024-01-02", "sales": 1350},
        ]

        return [ChartCardRecord(
            kind=cls.kind,
            report_id=cls.report_id,
            card_id=cls.card_id,
            data=ChartCardData(data=data)
        )]

# Register the card
SalesCard(app).as_route(app=app)
```

Access your card at: `GET /api/cards/sales_overview`

## ✨ Key Features

### 🏗️ **Multiple Transport Protocols**

- **HTTP**: Traditional REST endpoints for static data
- **WebSocket**: Real-time bidirectional communication
- **Streaming HTTP**: Server-Sent Events for live data feeds

### 📊 **Rich Card Types**

- **Chart Cards**: Line, bar, area, pie, radar, and radial charts
- **Table Cards**: Sortable, filterable data tables
- **Number Cards**: KPIs with trend indicators
- **Markdown Cards**: Rich text and documentation
- **HTML/Iframe Cards**: Custom content embedding

### 🔧 **Developer Experience**

- **Type Safety**: Full Pydantic validation and type hints
- **Auto-Generated Routes**: Minimal boilerplate code
- **Flexible Data Sources**: Database, API, or custom integrations
- **Error Handling**: Built-in resilience and graceful degradation

## 📖 Documentation

| Guide                                        | Description                                   |
| -------------------------------------------- | --------------------------------------------- |
| [Installation & Setup](docs/installation.md) | Complete installation and configuration guide |
| [Quick Start Tutorial](docs/quickstart.md)   | Build your first dashboard in 10 minutes      |
| [Card Types Reference](docs/card-types.md)   | Complete guide to all supported card types    |
| [Transport Protocols](docs/transport.md)     | HTTP, WebSocket, and streaming patterns       |
| [API Reference](docs/api-reference.md)       | Complete SDK API documentation                |
| [Deployment Guide](docs/deployment.md)       | Production deployment strategies              |
| [Examples](docs/examples/)                   | Real-world implementation examples            |

## 🏃‍♂️ Quick Examples

### Real-time WebSocket Card

```python
class LivePricesCard(BaseCard[ChartCardRecord]):
    transport = "websocket"

    @classmethod
    async def handler(cls, ctx):
        while True:
            price_data = await fetch_live_prices()
            yield ChartCardRecord(...)
            await asyncio.sleep(1)
```

### Streaming HTTP Card

```python
class MetricsStreamCard(BaseCard[NumberCardRecord]):
    transport = "streaming-http"

    @classmethod
    async def handler(cls, ctx):
        async for metric in metrics_generator():
            yield NumberCardRecord(...)
```

### Database Integration

```python
class UserStatsCard(BaseCard[TableCardRecord]):
    @classmethod
    async def handler(cls, ctx):
        async with database.transaction():
            users = await User.fetch_analytics()

        return [TableCardRecord(
            data=TableCardData(
                rows=[u.dict() for u in users],
                columns=["name", "signup_date", "activity"]
            )
        )]
```

## 🏗️ Architecture

Cereon SDK follows a **card-based architecture** where each card represents a self-contained data visualization component:

```
┌─────────────────┐    ┌─────────────────┐    ┌─────────────────┐
│   Dashboard     │◄───│   Cereon SDK    │◄───│  Data Sources   │
│   Frontend      │    │   (FastAPI)     │    │  (DB/APIs/etc)  │
└─────────────────┘    └─────────────────┘    └─────────────────┘
        │                       │                       │
        │                       │                       │
    React Components       Card Classes            Your Logic
```

### Core Components

- **BaseCard**: Abstract base class for all dashboard cards
- **Transport Protocols**: HTTP, WebSocket, and streaming support
- **Type System**: Pydantic models for validation and serialization
- **Route Generation**: Automatic FastAPI route creation

## 🔌 Integration with Cereon Dashboard

Cereon SDK is designed to work seamlessly with [@cereon/dashboard](https://www.npmjs.com/package/@cereon/dashboard):

**Backend (Python)**:

```python
# Your FastAPI card
class RevenueCard(BaseCard[ChartCardRecord]):
    # ... implementation
```

**Frontend (React)**:

```tsx
import { Dashboard } from "@cereon/dashboard";

const spec = {
  reports: [
    {
      reportCards: [
        {
          kind: "line",
          query: {
            variant: "http",
            payload: { url: "/api/cards/revenue" },
          },
        },
      ],
    },
  ],
};

<Dashboard state={{ spec }} />;
```

## 🧪 Testing

```bash
# Run tests
pytest

# With coverage
pytest --cov=cereon_sdk

# Integration tests
pytest tests/integration/
```

## 🤝 Contributing

We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.

1. Fork the repository
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request

## 📄 License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## 🆘 Support & Community

- 📚 **Documentation**: [Full documentation](docs/)
- 🐛 **Issues**: [GitHub Issues](https://github.com/adimis-ai/cereon/issues)
- 💬 **Discussions**: [GitHub Discussions](https://github.com/adimis-ai/cereon/discussions)
- 🚀 **Examples**: [Live Examples](docs/examples/)

---

_Need help getting started? Check out our [Quick Start Guide](docs/quickstart.md) or browse the [examples](docs/examples/)._
