Skip to main content

Common webapp scaffolding.

Project description

lassen

40.4881° N, 121.5049° W

Core utilities for MonkeySee web applications.

Not guaranteed to be backwards compatible, use at your own risk.

Structure

Stores: Each model is expected to have its own store. Base classes that provide standard logic are provided by lassen.store

  • StoreBase: Base class for all stores
  • StoreFilterMixin: Mixin for filtering stores that specify an additional schema to use to filter

Datasets: Optional huggingface datasets processing utilities. Only installed under the lassen[datasets] extra. These provide support for:

  • batch_to_examples: Iterate and manipulate each example separately, versus over nested key-based lists.
  • examples_to_batch: Takes the output of a typehinted element-wise batch and converts into the format needed for dataset insertion. If datasets can't automatically interpret the type of the fields, also provide automatic casting based on the typehinted dataclass.
from lassen.datasets import batch_to_examples, examples_to_batch
import pandas as pd

@dataclass
class BatchInsertion:
    texts: list[str]

def batch_process(examples):
    new_examples : list[BatchInsertion] = []
    for example in batch_to_examples(examples):
        new_examples.append(
            BatchInsertion(
                example["raw_text"].split()
            )
        )

    # datasets won't be able to typehint a dataset that starts with an empty example, so we use our explicit schema to cast the data
    return examples_to_batch(new_examples, BatchInsertion, explicit_schema=True)

df = pd.DataFrame(
    [
        {"raw_text": ""},
        {"raw_text": "This is a test"},
        {"raw_text": "This is another test"},
    ]
)

dataset = Dataset.from_pandas(df)

dataset = dataset.map(
    batch_process,
    batched=True,
    batch_size=1,
    num_proc=1,
    remove_columns=dataset.column_names,
)

Migrations: Lassen includes a templated alembic.init and env.py file. Client applications just need to have a migrations folder within their project root. After this you can swap poetry run alembic with poetry run migrate.

poetry run migrate upgrade head

Settings: Application settings should subclass our core settings. This provides a standard way to load settings from environment variables and includes common database keys.

from lassen.core.config import CoreSettings, register_settings

@register_settings
class ClientSettings(CoreSettings):
    pass

Schemas: For helper schemas when returning results via API, see lassen.schema.

Development

poetry install --extras "datasets"

createuser lassen
createdb -O lassen lassen_db
createdb -O lassen lassen_test_db

Unit Tests:

poetry run pytest

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

lassen-0.1.2.tar.gz (28.2 kB view details)

Uploaded Source

Built Distribution

lassen-0.1.2-py3-none-any.whl (25.5 kB view details)

Uploaded Python 3

File details

Details for the file lassen-0.1.2.tar.gz.

File metadata

  • Download URL: lassen-0.1.2.tar.gz
  • Upload date:
  • Size: 28.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.1 CPython/3.10.4 Darwin/22.4.0

File hashes

Hashes for lassen-0.1.2.tar.gz
Algorithm Hash digest
SHA256 dbcb21c762c5582db2f441351ad189e3f6d781cc4541a6c061f55290b66a772c
MD5 59e404cd2135c1e2311a7cde5ab7f585
BLAKE2b-256 ce3c6b077ac98dafc69f5f71497b55b8e48bafe2aa781c73a964948e2e5bb39c

See more details on using hashes here.

File details

Details for the file lassen-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: lassen-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 25.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.1 CPython/3.10.4 Darwin/22.4.0

File hashes

Hashes for lassen-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 562adf8b7cdbcec627912c6b2fab7d013ccbe8bb62338513710603555ff402c9
MD5 c6a65d68860a2d8784f3214659caa87b
BLAKE2b-256 f635cdb5562cfc20eed71202f0a8e0dc340490e26ece79cf50286a66b4202055

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page