Skip to main content

Assembly is a pythonic object-oriented, mid stack, batteries included framework built on Flask, that adds structure to your Flask application, and group your routes by class.Assembly allows developers to build web applications in much the same way they would build any other object-oriented Python program.Assembly Makes Flask Great Again!

Project description

Assembly

A Pythonic Object-Oriented Web Framework built on Flask


Assembly is a pythonic object-oriented, mid stack, batteries included framework built on Flask, that adds structure to your Flask application, and group your routes by class.

Assembly allows you to build web applications in much the same way you would build any other object-oriented Python program.

Assembly helps you create small to enterprise level applications easily.

Assembly Makes Flask Great Again!


Assembly Documentation

Assembly Version: 1.x.x


Assembly in action

# views.py

from assembly import (Assembly, response, request, HTTPError)

# Extends to Assembly makes it a route automatically
# By default, Index will be the root url
class Index(Assembly):

    # index is the entry route
    # -> /
    index(self):
        return "welcome to my site"

    # method name becomes the route
    # -> /hello/
    hello(self):
        return "I am a string"

    # undescore method name will be dasherize
    # -> /about-us/
    about_us(self):
        return "I am a string"


# The class name is part of the url prefix
# This will become -> /blog
class Blog(Assembly):

    # index will be the root 
    # -> /blog/
    index(self):
        return [
            {
                "title": "title 1",
                "content": "content"
            },
            ...
        ]

    # with params. The order will be respected
    # -> /comments/1234/
    # 1234 will be passed to the id
    comments(self, id):
        return [
            {
                comments...
            }
        ]


# It's also Restful
class Api(Assembly):

    # method named get, automatically accepts get method
    # -> GET /api/
    get(self):
        return {
            "message": "This will show on get call"
        }

    # method named post, automatically accepts post method
    # -> POST /api/
    post(self):
        return {
            "message": "This will show on POST call"
        }

    # Can change the response to json
    # -> /api/about/
    @response.json
    about(self): 
        return {
            "name": "Assembly",
            "version": "1.0.1"
        }

    # endpoint with different method 
    # -> POST /api/submit/
    @request.post
    submit(self):
        return {
            "message": "This will show on POST call only"
        }

    # This will throw an Unauthorize error
    error(self):
        raise HTTPError.Unauthorized()


Decisions made for you + Features

  • Smart routing: automatically generates routes based on the classes and methods in your views

  • Class name as the base url, ie: class UserAccount will be accessed at '/user-account'

  • Class methods (action) could be accessed: hello_world(self) becomes 'hello-world'

  • RESTful API

  • Automatic view rendering

  • Auto route can be edited with @route()

  • Markdown friendly. Inclusion of a markdown file will turn into HTML

  • BCRYPT is chosen as the password hasher

  • Session: Redis, AWS S3, Google Storage, SQLite, MySQL, PostgreSQL

  • Database/ORM: Active-Alchemy (SQLALchemy wrapper)

  • CSRF on all POST

  • Idiomatic HTTP error responses

  • Storage: Local, S3, Google Storage Flask-Cloudy

  • Mailer (SES or SMTP)

  • Arrow for date and time

  • Caching

  • JWT

  • Pagination

  • Signals: to dispatch messages and data to other part of the application

  • Markdown

  • Jinja2 for templating language

  • Multi application

  • Web Assets

  • CLI

  • Inbuilt development server


Quickstart

This quickstart will allow us to go with Assembly from 0 to 100!

1. Install Assembly

Install Assembly with pip install assembly

It is highly recommended to use a virtualenv, in this case let's use VirtualenvWrapper (you can use any that is convenient for you)

mkvirtualenv my-first-app

workon my-first-app

pip install assembly

2. Initialize your application

Initialize Assembly with asm-admin init

CD into the folder you intend to create the application, then run asm-admin init. This will setup the structure along with the necessary files to get started


cd app-dir

asm-admin init

Upon initialization you should have a structure similar to this:

-- /
    |- wsgi.py
    |- config.py
    |- requirements.txt
    |- main
        |- __init__.py
        |- __models__.py
        |- templates
            |- Index
                |- index.html
            |- layouts
                |- base.html
        |- static
        |- cli.py

    |- __data__/

3. Edit your first view


# main/__init__.py

from assembly import (Assembly, response)

class Index(Assembly):

    index(self):
        return {
            "title": "Assembly is awesome",
            "content": "That is a true fact"
        }

    @response.json
    api(self):
        return {
            "name": "Assembly",
            "version": "x-to-infinity"
        }

4. Edit your template

4.0 Edit base layout

<!-- main/templates/layouts/base.html -->

<!doctype html>
<html lang="en">
  <head>
    <title>{% block title %}{% endblock %}</title>
  </head>

  <body>
    <div class="container">
      {% block body %}{% endblock %}
    </div>
  </body>
</html>

4.1 Edit Index/index.html


<!-- main/templates/Index/index.html -->

{% extends 'main/layouts/base.html' %}

{% block title %}Welcome to my Assembly Site {% endblock %}

{% block body %}
    <div>
        <h1>{{ title }}</h1>
    </div>
    <div>
        {{ content }}
    </div>
{% endblock %}


5. Serve your first application

If everything is all set, all you need to do now is run your site:

asm-admin serve

It will start serving your application by default at 127.0.0.1:5000

Two endpoints will be available:

  • http://127.0.0.1:5000/ which will show an HTML
  • http://127.0.0.1:5000/api/ which will a json response

Learn More: Assembly Documentation


License MIT

Copyright: 2020 - Forever Mardix

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

Assembly-1.2.0.tar.gz (159.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

Assembly-1.2.0-py2-none-any.whl (244.8 kB view details)

Uploaded Python 2

File details

Details for the file Assembly-1.2.0.tar.gz.

File metadata

  • Download URL: Assembly-1.2.0.tar.gz
  • Upload date:
  • Size: 159.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.8.0 tqdm/4.35.0 CPython/2.7.13

File hashes

Hashes for Assembly-1.2.0.tar.gz
Algorithm Hash digest
SHA256 746e5eaf18df3a19169f07b6dbe327215ad19187e9f17cfe9e1737da9cf97e3c
MD5 c3e95186a9a4ce80234b03b925a699f8
BLAKE2b-256 945db26d9ba16a9944bc3885b250bbe2b0f504a86213ab290eda1e6e418df0dd

See more details on using hashes here.

File details

Details for the file Assembly-1.2.0-py2-none-any.whl.

File metadata

  • Download URL: Assembly-1.2.0-py2-none-any.whl
  • Upload date:
  • Size: 244.8 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.8.0 tqdm/4.35.0 CPython/2.7.13

File hashes

Hashes for Assembly-1.2.0-py2-none-any.whl
Algorithm Hash digest
SHA256 ac0dfe331d203c05b640464df45cbd3564a28b6d676b47e9366abeca4061be3e
MD5 fcec788ba54929b1697105c0ddcbb255
BLAKE2b-256 324de0b98dd0f9e399201d58f118f192bde9dcf78e0b60cc4731bb9ee25af092

See more details on using hashes here.

Supported by

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