Metadata-Version: 2.4
Name: yeriasdk
Version: 1.5.0
Summary: A modern Python SDK for generating dynamic JSON interfaces
Author: Numerum
License: Apache-2.0
Project-URL: Homepage, https://github.com/yeria-app/yeriasdk
Project-URL: Repository, https://github.com/yeria-app/yeriasdk.git
Project-URL: Issues, https://github.com/yeria-app/yeriasdk/issues
Keywords: json,interface,form-builder,sdk,dynamic-ui,mobile-apps
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
License-File: NOTICE
Requires-Dist: cryptography>=41.0.0
Requires-Dist: markdown>=3.4.0
Requires-Dist: bleach>=6.0.0
Requires-Dist: requests>=2.28.0
Provides-Extra: dev
Requires-Dist: pytest>=7.4.0; extra == "dev"
Requires-Dist: pytest-cov>=4.1.0; extra == "dev"
Requires-Dist: black>=23.0.0; extra == "dev"
Requires-Dist: mypy>=1.5.0; extra == "dev"
Requires-Dist: ruff>=0.0.280; extra == "dev"
Dynamic: license-file

# Yeria Python SDK

> **Note**: This is the Python port of the Yeria SDK. This repository is a monorepo containing multiple language implementations. See the [root README](../README.md) for an overview.

A stateless backend library for building views that are sent to renderers (mobile or web). This is the Python port of the TypeScript Yeria SDK.

🌐 Website: [yeria.app](https://yeria.app)
📱 Android app: [Yeria on Google Play](https://play.google.com/store/apps/details?id=com.numerum.yeria.app) — the renderer these views are built for.

## Features

- **Stateless Architecture**: No internal state, perfect for serverless and microservices
- **Ed25519 Signing**: Secure view signing and verification using Ed25519 cryptography
- **12 View Types**: Form, Reader, ActionList, ActionGrid, QRScan, QRDisplay, Message, Card, Carousel, Timeline, Media, Map
- **Notifications**: Send signed notifications to users via the Yeria platform
- **Type Safety**: Full type definitions using Python dataclasses and type hints
- **Validation**: Built-in field and form validation
- **Security**: XSS protection, URL validation, input sanitization

## Installation

```bash
pip install yeriasdk
```

## Quick Start

```python
from yeriasdk import YeriaApp, YeriaAppConfig
from yeriasdk.views import FormView

# Initialize YeriaApp
config = YeriaAppConfig(
    app_id="my-app",
    view_expiration_minutes=60,
)
app = YeriaApp(config)

# Create a form view
form = app.create_form_view("registration", "User Registration")
form.add_text_field("name", "Full Name", is_required=True)
form.add_email_field("email", "Email", is_required=True)
form.submit_button("Register")

# Serve with signature
response = app.serve(form)
print(response.view)  # The view JSON
print(response.signature)  # Ed25519 signature
```

### Identité visuelle du service

La couleur doit être au format `#RRGGBB`. Le canvas est automatiquement dérivé
de cette couleur, avec le même traitement que l'identité Yeria par défaut. La
configuration est incluse dans chaque vue signée. Le logo du service ne passe
pas par le SDK : il se téléverse dans la console fournisseur (registre Yeria,
soumis à la revue) et l'application l'affiche avant même la première vue.

Au-delà de `primary`, cinq clés facultatives (offre Premium) : `primary_dark`
et `secondary_dark` (mode sombre), `secondary` (pastilles, puces, anneaux de
progression), `font` (`default`, `inter`, `nunito`, `poppins`, `serif`) et
`shape` (`rounded`, `soft`, `square`). Le SDK ignore l'offre du service :
l'application borne un service gratuit à `primary`.

```python
from yeriasdk import ServiceBranding, YeriaApp, YeriaAppConfig

app = YeriaApp(YeriaAppConfig(
    app_id="my-app",
    branding=ServiceBranding(
        primary="#E85D04",
        primary_dark="#FFB870",
        secondary="#168A5B",
        font="poppins",
        shape="soft",
    ),
))
```

## Notifications

```python
from yeriasdk import YeriaApp, YeriaAppConfig, Notification

app = YeriaApp(YeriaAppConfig(
    app_id="my-backend-service",
    private_key=private_key_pem,
    base_url="https://yeria.app",
))

app.notify(Notification("user-123", "Bienvenue !", "Merci d'avoir rejoint Yeria"))
```

`POST {base_url}/api/v1/provider/services/{app_id}/notifications`. L'appel ne
porte aucun jeton : la signature Ed25519 du service l'authentifie.

### Depuis un déploiement de développement

Le tableau de bord fournisseur rend un identifiant `devkey_...` après
l'enregistrement de l'URL et de la clé publique de votre déploiement de travail.
Reportez-le dans `dev_key_id` :

```python
app = YeriaApp(YeriaAppConfig(
    app_id="my-backend-service",
    private_key=dev_private_key_pem,   # la clé de développement
    base_url="https://yeria.app",
    dev_key_id="devkey_a3f9c81e04b2d675",
))
```

Sa présence indique à Yeria que l'appel vient de votre déploiement de travail,
sa valeur désigne la ligne qui vérifie la signature. Vaut pour `notify` et
`fetch_user_details` ; la rotation de clé est refusée (403). Le réglage expire
seul — 30 jours par défaut, 90 au maximum. **À laisser vide en production.**

## Yeria Links

`YeriaLink` generates canonical links without making a network request. HTTPS
is the default so the same link can be displayed on a website or inside an
application.

```python
from yeriasdk import CardView, ReaderView, YeriaLink

chat_url = YeriaLink.chat("catalog-service")
# https://yeria.app/dl/c/catalog-service

component_url = YeriaLink.component(
    "catalog-service",
    "/orders?mode=edit",
)

reader = ReaderView("links", "Useful links")
reader.add_link(chat_url, "Open chat")

card = CardView("order", "Order").set_description("Order details")
card.add_action("Edit", "GET", href=component_url)

# For an application that already knows Yeria is installed:
compact_url = YeriaLink.pin("catalog-service", format="yeria")
# yeria://dl/p/catalog-service
```

Available methods are `service`, `component`, `chat`, `pin`, and `subscribe`.
Service IDs are URL-safe strings and component paths must remain relative to
the service.

## Static JSON Views

```python
from yeriasdk import YeriaApp, YeriaAppConfig

app = YeriaApp(YeriaAppConfig(app_id="my-app"))

envelope = app.serve_raw_view(
    {
        "id": "home-static",
        "type": "Reader",
        "content": {
            "title": "Bienvenue",
            "body": [
                {"type": "paragraph", "text": "Cette vue vient d'un bloc JSON."}
            ],
        },
    }
)
print(envelope.payload)
print(envelope.signature)
```

## View Types

### FormView
Create forms with various field types (text, email, password, select, file, GPS, etc.)

### ReaderView
Display rich content with paragraphs, images, markdown, tables, code blocks, etc.

### ActionListView / ActionGridView
Display lists or grids of actions

### QRScanView / QRDisplayView
QR code scanning and display

### MessageView
Display messages with actions

### CardView
Display card-based content with stats and sections

### CarouselView
Display carousel slides

### TimelineView
Display chronological events

### MediaView
Display audio and video playlists

### MapView
Display geographic data on maps

## API Parity

The Python SDK maintains API parity with the TypeScript version:

- Same factory methods: `app.create_form_view()`, `app.create_reader_view()`, etc.
- Same fluent API: `view.add_field().set_intro().submit_button()`
- `set_note()` remains available for backward compatibility but is deprecated
  and ignored by the mobile renderer; use `set_intro()` or `add_paragraph()`
- Same validation and security features
- Same Ed25519 signing and verification

## Examples

See `examples/basic_usage.py` for a complete example.

## Requirements

- Python 3.10+
- cryptography (for Ed25519)
- markdown (for ReaderView markdown support)
- bleach (for HTML sanitization)
- requests (for sending notifications)

## Status

✅ Core classes (BaseView, YeriaApp)  
✅ All 12 view types  
✅ Type definitions  
✅ Error handling  
✅ Validation utilities  
✅ Ed25519 signing/verification  
✅ Examples  


## License

Ce projet est sous licence Apache 2.0. Voir les fichiers `LICENSE` et `NOTICE` pour plus de détails. Copyright 2026 Numerum.
