Skip to main content

Decorate your project with some fashionable supermodels

Project description

fashionable

PyPI version Python version Build Status codecov

Decorate your project with some fashionable supermodels.

Decorator example

from typing import Set

from fashionable import fashionable

@fashionable
def bits_to_binary_like(bits: Set[int], length: int = 8) -> int:
    bits.add(0)
    return ''.join(str(int(b in bits)) for b in range(length, 0, -1))

bits_to_binary_like('334455')  # 11100

Model example

from typing import List, Optional

from fashionable import Attribute, Model


class Project(Model):
    id = Attribute(str, max=32)
    name = Attribute(str)
    organization = Attribute(Optional[str])
    domain = Attribute(Optional[str])
    links = Attribute(Optional[List[str]])
    
project = Project(1, 'Test')

Supermodel example with Sanic

from typing import List, Optional

from fashionable import Attribute, Supermodel
from sanic import Sanic
from sanic.response import json, HTTPResponse

app = Sanic()
app.db = ...

class Project(Supermodel):
    _ttl = 300
    id = Attribute(str, max=32)
    name = Attribute(str)
    organization = Attribute(Optional[str])
    domain = Attribute(Optional[str])
    links = Attribute(Optional[List[str]])
    
    @staticmethod
    async def _create(raw: dict):
        await app.db.project_create(raw)

    @staticmethod
    async def _get(id_: str) -> Optional[dict]:
        return await app.db.project_get(id_)

    @staticmethod
    async def _update(id_: str, raw: dict):
        await app.db.project_update(id_, raw)

    @staticmethod
    async def _delete(id_: str):
        await app.db.project_delete(id_)


@app.get('/project/<id_>')
async def project_get(request, id_):
    project = await Project.get(id_)
    return json(project)


@app.post('/project')
async def project_create(request):
    project = await Project.create(**request.json)
    return json(
        project,
        status=201,
        headers={'Location': '/project/' + project.id},
    )


@app.put('/project/<id_>')
async def project_update(request, id_):
    project = await Project.get(id_, fresh=True)
    await project.update(**request.json)
    return json(project)


@app.delete('/project/<id_>')
async def project_delete(request, id_):
    project = await Project.get(id_, fresh=True)
    await project.delete()
    return HTTPResponse(status=204)


if __name__ == '__main__':
    app.run(host='0.0.0.0', port=8000)

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

fashionable-0.12.3.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

fashionable-0.12.3-py3-none-any.whl (14.8 kB view details)

Uploaded Python 3

File details

Details for the file fashionable-0.12.3.tar.gz.

File metadata

  • Download URL: fashionable-0.12.3.tar.gz
  • Upload date:
  • Size: 11.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for fashionable-0.12.3.tar.gz
Algorithm Hash digest
SHA256 7510cd958fa2a679b061d66347ec6b867d151d0d83b8d4449abb9b94edf2725d
MD5 f6aa31beb922eb7a45b97b39fde90f4c
BLAKE2b-256 c256c5dd4b837a574593e4df54fc2d33e16da55e3f272be6ed03bb40907415d3

See more details on using hashes here.

File details

Details for the file fashionable-0.12.3-py3-none-any.whl.

File metadata

  • Download URL: fashionable-0.12.3-py3-none-any.whl
  • Upload date:
  • Size: 14.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for fashionable-0.12.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ff1ca2729a392281ed7bddabcd1f649d61e57f7b1884feaefea52d0a88cc6504
MD5 4d8b2203f0f676c6ea1dc3cf12931d28
BLAKE2b-256 117458f552c630479a662858cdf48b339f7fac8cbd1c014949cc13b4667ed304

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