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 datamodel 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
Schemas: Each datamodel should define a Model class (SQLAlchemy base object) and a series of Schema objects (Pydantic) that allow the Store to serialize the models. These schemas are also often used for direct CRUD referencing in the API layer.
We use a base Stub
file to generate these schemas from a centralized definition. When defining generators you should use a path that can be fully managed by lassen, since we will remove and regenerate these files on each run.
STORE_GENERATOR = StoreGenerator("models/auto")
SCHEMA_GENERATOR = SchemaGenerator("schemas/auto")
poetry run generate-lassen
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file lassen-0.2.6.tar.gz
.
File metadata
- Download URL: lassen-0.2.6.tar.gz
- Upload date:
- Size: 44.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.1 CPython/3.10.4 Darwin/22.5.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b3dd66db9fbab246386a731de378e829ce848b5e38946181c88ac0d65a46483c |
|
MD5 | 5ddcbee95fc20eb39c8e26da15e1f5e6 |
|
BLAKE2b-256 | 1cf3970eeb3e935824fdc4424f0b794735613895270fba1515b9e10b7566fe5b |
File details
Details for the file lassen-0.2.6-py3-none-any.whl
.
File metadata
- Download URL: lassen-0.2.6-py3-none-any.whl
- Upload date:
- Size: 48.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.1 CPython/3.10.4 Darwin/22.5.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 69ba3059fa2d421bcfff6b243777cce0b62a173ff9ad26cdbf0181814ef1c588 |
|
MD5 | a85b6ccba0e7f1d6b97f38c54f496f3b |
|
BLAKE2b-256 | 199556e2b969c7a06f6fc9b44b788041d9a1fed990263ae3b535f7811930d5e2 |