Skip to main content

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)

Release files for fashionable 0.12.3

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

Source distribution (sdist)

Source distribution for fashionable 0.12.3
File Size Uploaded
fashionable-0.12.3.tar.gz 11.7 kB Details

Built distribution (wheel)

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

Total release size: 26.5 kB

Release files / fashionable-0.12.3.tar.gz

Download URL fashionable-0.12.3.tar.gz
Size 11.7 kB
Tags Source
SHA-256 checksum
How to use checksums
7510cd958fa2a679b061d66347ec6b867d151d0d83b8d4449abb9b94edf2725d
BLAKE2b-256 checksum
How to use checksums
c256c5dd4b837a574593e4df54fc2d33e16da55e3f272be6ed03bb40907415d3
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / fashionable-0.12.3-py3-none-any.whl

Download URL fashionable-0.12.3-py3-none-any.whl
Size 14.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ff1ca2729a392281ed7bddabcd1f649d61e57f7b1884feaefea52d0a88cc6504
BLAKE2b-256 checksum
How to use checksums
117458f552c630479a662858cdf48b339f7fac8cbd1c014949cc13b4667ed304
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

0.12.3 This release

2 release files

0.11.1

2 release files

0.11.0

2 release files

0.10.3

2 release files

0.10.2

2 release files

0.10.1

2 release files

0.10.0

2 release files

0.9.0

1 release file

0.8.5

1 release file

0.8.4

1 release file

0.8.3

1 release file

0.8.2

1 release file

0.8.1

1 release file

0.8.0

1 release file

0.7.0

1 release file

0.6.0

1 release file

0.5.0

1 release file

0.4.0

1 release file

0.3.1

1 release file

0.3.0

1 release file

0.2.4

1 release file

0.2.3

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.2.0

1 release file

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