Skip to main content

lila

https://github.com/KillAChicken/lila/workflows/Tests/badge.svg

Lila is a Python library to work with Siren protocol. It aims to encapsulate most of the requirements of the protocol, so that one can utilize EAFP principle instead of validating incoming and outgoing data.

Installation

$ python -m pip install lila

Documentation

Documentation for the package can be found on the Wiki.

Quickstart

Assume we expect to receive or need to send the following json data:

entity_data = {
  "class": [ "order" ],
  "properties": {
      "orderNumber": 42,
      "itemCount": 3,
      "status": "pending"
  },
  "entities": [
    {
      "class": [ "items", "collection" ],
      "rel": [ "http://x.io/rels/order-items" ],
      "href": "http://api.x.io/orders/42/items"
    },
    {
      "class": [ "info", "customer" ],
      "rel": [ "http://x.io/rels/customer" ],
      "properties": {
        "customerId": "pj123",
        "name": "Peter Joseph"
      },
      "links": [
        { "rel": [ "self" ], "href": "http://api.x.io/customers/pj123" }
      ]
    }
  ],
  "actions": [
    {
      "name": "add-item",
      "title": "Add Item",
      "method": "POST",
      "href": "http://api.x.io/orders/42/items",
      "type": "application/x-www-form-urlencoded",
      "fields": [
        { "name": "orderNumber", "type": "hidden", "value": "42" },
        { "name": "productCode", "type": "text" },
        { "name": "quantity", "type": "number" }
      ]
    }
  ],
  "links": [
    { "rel": [ "self" ], "href": "http://api.x.io/orders/42" },
    { "rel": [ "previous" ], "href": "http://api.x.io/orders/41" },
    { "rel": [ "next" ], "href": "http://api.x.io/orders/43" }
  ]
}

One can parse these data into a python object and access parts of it (client-side):

from lila.serialization.json.parser import JSONParser

entity = JSONParser().parse_entity(entity_data)

assert entity.actions[0].fields[0].value == "42"

Or start with a python object and build this json (server-side):

from lila.core.field import InputType, Field
from lila.core.action import Method, Action
from lila.core.link import Link, EmbeddedLink
from lila.core.entity import Entity, EmbeddedRepresentation
from lila.serialization.json.marshaler import JSONMarshaler

entity = Entity(
    classes=["order"],
    properties={
        "orderNumber": 42,
        "itemCount": 3,
        "status": "pending",
    },
    entities=[
        EmbeddedLink(
            classes=["items", "collection"],
            relations=["http://x.io/rels/order-items"],
            target="http://api.x.io/orders/42/items",
        ),
        EmbeddedRepresentation(
            classes=["info", "customer"],
            relations=["http://x.io/rels/customer"],
            properties={
                "customerId": "pj123",
                "name": "Peter Joseph",
            },
            links=[
                Link(
                    relations=["self"],
                    target="http://api.x.io/customers/pj123",
                ),
            ],
        ),
    ],
    actions=[
        Action(
            name="add-item",
            title="Add Item",
            method=Method.POST,
            target="http://api.x.io/orders/42/items",
            media_type="application/x-www-form-urlencoded",
            fields=[
                Field(
                    name="orderNumber",
                    input_type=InputType.HIDDEN,
                    value="42"
                ),
                Field(
                    name="productCode",
                    input_type=InputType.TEXT,
                ),
                Field(
                    name="quantity",
                    input_type=InputType.NUMBER,
                ),
            ]
        )
    ],
    links=[
        Link(
            relations=["self"],
            target="http://api.x.io/orders/42",
        ),
        Link(
            relations=["previous"],
            target="http://api.x.io/orders/41",
        ),
        Link(
            relations=["next"],
            target="http://api.x.io/orders/43",
        ),
    ]
)

entity_data = JSONMarshaler().marshal_entity(entity)

assert entity_data["actions"][0]["fields"][0]["value"] == "42"

Metadata

Release files for lila 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lila 1.0.0
File Size Uploaded
lila-1.0.0.tar.gz 14.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for lila 1.0.0
File Interpreter ABI Platform
lila-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 35.2 kB

Release files / lila-1.0.0.tar.gz

Download URL lila-1.0.0.tar.gz
Size 14.6 kB
Tags Source
SHA-256 checksum
How to use checksums
85aaa2cf71aa7b3e3594f827120e3a6fb6bb016c055bcc5c232007279c66f1d1
BLAKE2b-256 checksum
How to use checksums
0f231cbcc8490bd4535fc928d4aa3e07d2e2c570ef043f48cb7847d8d46b6a1f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.5.2

Release files / lila-1.0.0-py3-none-any.whl

Download URL lila-1.0.0-py3-none-any.whl
Size 20.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ae7f6a86c46cbead02b3aa4b4c21c4e431e3093a68cf5102925a9b5d1c86d846
BLAKE2b-256 checksum
How to use checksums
d7ce218bc32366ce325c967f1044c64a5c794dba6fcfd44bb417618e5ae9b012
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.5.2

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page