# flask-boiler
[![Build Status](https://travis-ci.com/billyrrr/flask-boiler.svg?branch=master)](https://travis-ci.com/billyrrr/flask-boiler)
[![Coverage Status](https://coveralls.io/repos/github/billyrrr/flask-boiler/badge.svg?branch=master)](https://coveralls.io/github/billyrrr/flask-boiler?branch=master)
[![Documentation Status](https://readthedocs.org/projects/flask-boiler/badge/?version=latest)](https://flask-boiler.readthedocs.io/en/latest/?badge=latest)
"boiler": **B**ackend-**O**riginated **I**nstantly-**L**oaded **E**ntity **R**epository
Note: in Context, a proxy is configured to support Firestore
operation in China; This may result in safety issues. Make sure
that this setting is okay with you. If not, raise an issue.
```
"""
TODO: NOTE that PROXY is used here
Best be replaced for Safety reasons
ATTENTION:
"""
os.environ["HTTP_PROXY"] = "http://34.85.42.121:8899"
os.environ["HTTPS_PROXY"] = "http://34.85.42.121:8899"
```
Flask-boiler manages your application state with Firestore.
You can create view models that aggregates underlying data
sources and store them immediately and permanently in Firestore.
As a result, your front end development will be as easy as
using Firestore. Flask-boiler is comparable to Spring Web Reactive.
Demo:
When you change the attendance status of one of the participants
in the meeting, all other participants receive an updated version
of the list of people attending the meeting.
![Untitled_2](https://user-images.githubusercontent.com/24789156/71137341-be0e1000-2242-11ea-98cb-53ad237cac43.gif)
Some reasons that you may want to use this framework or architectual
practice:
- You want to build a reactive system and not just a reactive view.
- You want to build a scalable app that is native to distributed
systems.
- You want a framework with a higher level of abstraction, so you can
exchange components such as transportion protocols
- You want your code to be readable and clear and written mostly
in python, while maintaining compatibility to different APIs.
- You have constantly-shifting requirements, and want to have
the flexibility to migrate different layers, for example,
switch from REST API to WebSocket to serve a resource.
This framework is at ***beta testing stage***.
API is not guaranteed and ***may*** change.
Documentations: [readthedocs](https://flask-boiler.readthedocs.io/)
Quickstart: [Quickstart](https://flask-boiler.readthedocs.io/en/latest/quickstart_link.html)
API Documentations: [API Docs](https://flask-boiler.readthedocs.io/en/latest/apidoc/flask_boiler.html)
Example of a Project using flask-boiler: [gravitate-backend](https://github.com/billyrrr/gravitate-backend)
[Related Technologies](https://medium.baqend.com/real-time-databases-explained-why-meteor-rethinkdb-parse-and-firebase-dont-scale-822ff87d2f87)
## Ideal Usage
boiler will compile your python code into flink jobs, web servers,
and more to be run on a kubernetes engine (not currently implemented).
![Ideal Usage](docs/distributed.png)
## Introduction
boiler is technically MVVM (Model-View-ViewModel), where,
1. Model consists of a transactional database or datastore, and
lives in back end.
2. ViewModel consists of a distributed state consists of Model and
aggregator. It is the main part of boiler. For client-read,
it receives the streams coming in from the Model layer, and
output them as a View to the View layer. For client-write,
it receives the change streams from View
layer, and operate on Model layer to persist the change.
ViewModel lives in the back end, and may be operated as
boiler python code, or compiled as flink jobs in the case of
big data application (to be implemented).
3. View is the presentational layer for the back end. It serves
1NF normalized data that are readable to the front end
without further aggregation. Client reads and writes to View.
View should be ephemeral, and can be rebuilt from ViewModel.
View may be a remote system, eg. firestore or leancloud.
## Installation
In your project directory,
```
pip install flask-boiler
```
See more in [Quickstart](https://flask-boiler.readthedocs.io/en/latest/quickstart_link.html).
<!--## Usage-->
<!--### Business Properties Binding-->
<!--You can bind a view model to its business properties (underlying domain model).-->
<!--See `examples/binding_example.py`. (Currently breaking)-->
<!--```python-->
<!--vm: Luggages = Luggages.new(vm_ref)-->
<!--vm.bind_to(key=id_a, obj_type="LuggageItem", doc_id=id_a)-->
<!--vm.bind_to(key=id_b, obj_type="LuggageItem", doc_id=id_b)-->
<!--vm.register_listener()-->
<!--```-->
### State Management
You can combine information gathered in domain models and serve them in Firestore, so
that front end can read all data required from a single document or collection,
without client-side queries and excessive server roundtrip time.
There is a medium [article](https://medium.com/resolvejs/resolve-redux-backend-ebcfc79bbbea)
that explains a similar architecture called "reSolve" architecture.
See ```examples/meeting_room/view_models``` on how to use flask-boiler
to expose a "view model" in firestore that can be queried directly
by front end without aggregation.
### Processor Modes
`flask-boiler` is essentially a framework for source-sink operations:
```
Source(s) -> Processor -> Sink(s)
```
Take query as an example,
- Boiler
- NoSQL
- Flink
- staticmethods: converts to UDF
- classmethods: converts to operators and aggregator's
### Declare View Model
```python
class CityView(ViewModel):
name = attrs.bproperty()
country = attrs.bproperty()
@classmethod
def new(cls, snapshot):
store = CityStore()
store.add_snapshot("city", dm_cls=City, snapshot=snapshot)
store.refresh()
return cls(store=store)
@name.getter
def name(self):
return self.store.city.city_name
@country.getter
def country(self):
return self.store.city.country
@property
def doc_ref(self):
return CTX.db.document(f"cityView/{self.store.city.doc_id}")
```
### Document View
``` python
class MeetingSessionGet(Mediator):
from flask_boiler import source, sink
source = source.domain_model(Meeting)
sink = sink.firestore() # TODO: check variable resolution order
@source.triggers.on_update
@source.triggers.on_create
def materialize_meeting_session(self, obj):
meeting = obj
assert isinstance(meeting, Meeting)
def notify(obj):
for ref in obj._view_refs:
self.sink.emit(reference=ref, snapshot=obj.to_snapshot())
_ = MeetingSession.get(
doc_id=meeting.doc_id,
once=False,
f_notify=notify
)
# mediator.notify(obj=obj)
@classmethod
def start(cls):
cls.source.start()
```
### WebSocket View
```python
class Demo(WsMediator):
pass
mediator = Demo(view_model_cls=rainbow_vm,
mutation_cls=None,
namespace="/palette")
io = flask_socketio.SocketIO(app=app)
io.on_namespace(mediator)
```
### Create Flask View
You can use a RestMediator to create a REST API. OpenAPI3 docs will be
automatically generated in ```<site_url>/apidocs``` when you run ```_ = Swagger(app)```.
```python
app = Flask(__name__)
class MeetingSessionRest(Mediator):
# from flask_boiler import source, sink
view_model_cls = MeetingSessionC
rest = RestViewModelSource()
@rest.route('/<doc_id>', methods=('GET',))
def materialize_meeting_session(self, doc_id):
meeting = Meeting.get(doc_id=doc_id)
def notify(obj):
d = obj.to_snapshot().to_dict()
content = jsonify(d)
self.rest.emit(content)
_ = MeetingSessionC.get(
doc_id=meeting.doc_id,
没有合适的资源?快使用搜索试试~ 我知道了~
PyPI 官网下载 | flask_boiler-0.0.2.dev15.tar.gz
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 144 浏览量
2022-01-11
10:20:24
上传
评论
收藏 119KB GZ 举报
温馨提示
共168个文件
py:160个
txt:4个
pkg-info:2个
资源来自pypi官网。 资源全名:flask_boiler-0.0.2.dev15.tar.gz
资源推荐
资源详情
资源评论
收起资源包目录
PyPI 官网下载 | flask_boiler-0.0.2.dev15.tar.gz (168个子文件)
setup.cfg 79B
README.md 16KB
PKG-INFO 20KB
PKG-INFO 20KB
watch.py 30KB
pony_query_ported.py 27KB
test_dav.py 20KB
fields.py 18KB
firestore.py 17KB
attribute.py 14KB
query_delta.py 14KB
test_firestore_object.py 12KB
context.py 12KB
firestore_object.py 10KB
mixin.py 10KB
test_serializable.py 9KB
deploy.py 9KB
rest_api.py 9KB
test_view_model.py 8KB
test_domain_model.py 8KB
schema.py 7KB
test_schema.py 7KB
test_domain_model_attributed.py 7KB
query.py 7KB
test_domain_model_multiple.py 7KB
test_field.py 6KB
meeting_session.py 6KB
view_model.py 5KB
cmp.py 5KB
primary_object.py 5KB
test_database.py 4KB
color_fixtures.py 4KB
test_auth.py 4KB
__init__.py 4KB
query_mixin.py 4KB
test_query.py 4KB
gallery.py 4KB
base.py 4KB
distributed_counter_example.py 4KB
test_bpstore.py 4KB
test_view_model.py 4KB
config.py 4KB
store.py 3KB
business_property_store.py 3KB
view_example.py 3KB
test_delta_dav.py 3KB
test_models.py 3KB
document.py 3KB
test_sql.py 3KB
auth.py 3KB
test_view.py 3KB
binding_example.py 3KB
utils.py 3KB
mediators.py 3KB
tests.py 3KB
struct.py 3KB
leancloud.py 2KB
luggage_models.py 2KB
fixtures.py 2KB
testing_utils.py 2KB
test_context.py 2KB
snapshot_container.py 2KB
relationship_example.py 2KB
user_view.py 2KB
test_attribute.py 2KB
rest.py 2KB
websocket.py 2KB
aggregation.py 2KB
factory.py 2KB
domain_model.py 2KB
leancloud.py 2KB
collection_mixin.py 2KB
view.py 2KB
utils.py 2KB
test_ws.py 2KB
test_collection_mixin.py 2KB
conftest.py 2KB
setup.py 2KB
quickstart_example.py 2KB
registry.py 2KB
firestore.py 2KB
utils.py 1KB
test_deserialization.py 1KB
test_factory.py 1KB
base.py 1KB
rest_mediators.py 1KB
test_cmp.py 1KB
meta.py 1KB
retrofit.py 1KB
coordinator.py 1KB
mutation.py 1KB
couchbase.py 1KB
test_relationships.py 1KB
referenced_object.py 1007B
quickstart.py 1005B
test_model_registry.py 1003B
test_source.py 991B
mediators.py 986B
test_store.py 914B
meeting_session_ops.py 889B
共 168 条
- 1
- 2
资源评论
挣扎的蓝藻
- 粉丝: 13w+
- 资源: 15万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功