Skip to content

Commit 95dec53

Browse files
author
Peter
committed
Inlined README.rst into setup.py
1 parent aa515fd commit 95dec53

File tree

2 files changed

+64
-64
lines changed

2 files changed

+64
-64
lines changed

README.rst

Lines changed: 0 additions & 61 deletions
This file was deleted.

setup.py

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,69 @@
11
from distutils.core import setup
22

33

4-
with open('README.rst') as fp:
5-
readme = fp.read()
4+
readme = """
5+
SUMMARY
6+
-------
7+
8+
Flask\_replicated is a Flask extension, designed to work with
9+
SqlAlchemy. It's purpose it to provide more or less automatic
10+
master-slave replication. On each request, extension determines database
11+
usage intention (to read or to write into a database). Then, it picks
12+
right database url inside overriden db.get\_engine() whenever request
13+
handler tries to access database.
14+
15+
INSTALLATION
16+
------------
17+
18+
1. Install flask\_replicated distribution using "python setup.py
19+
install".
20+
21+
2. In flask app.config configure your database bindings a standard way:
22+
23+
::
24+
25+
SQLALCHEMY_DATABASE_URI = '%(schema)s://%(user)s:%(password)s@%(master_host)s/%(database)s'
26+
SQLALCHEMY_BINDS = {
27+
'master': SQLALCHEMY_DATABASE_URI,
28+
'slave': '%(schema)s://%(user)s:%(password)s@%(slave_host)s/%(database)s'
29+
}
30+
31+
3. Register app extension:
32+
33+
::
34+
35+
app = Flask(...)
36+
...
37+
FlaskReplicated(app)
38+
39+
USAGE
40+
-----
41+
42+
Flask\_replicated routes SQL queries into different databases based on
43+
request method. If method is one of READONLY\_METHODS which are defined
44+
as set(['GET', 'HEAD'])
45+
46+
While this is usually enough there are cases when DB access is not
47+
controlled explicitly by your business logic. Good examples are implicit
48+
creation of sessions on first access, writing some bookkeeping info,
49+
implicit registration of a user account somewhere inside the system.
50+
These things can happen at arbitrary moments of time, including during
51+
GET requests.
52+
53+
To handle these situations wrap appropriate view function with
54+
@flask\_replicated.changes\_database decorator. It will mark function to
55+
always use master database url.
56+
57+
GET after POST
58+
~~~~~~~~~~~~~~
59+
60+
There is a special case that needs addressing when working with
61+
asynchronous replication scheme. Replicas can lag behind a master
62+
database on receiving updates. In practice this mean that after
63+
submitting a POST form that redirects to a page with updated data this
64+
page may be requested from a slave replica that wasn't updated yet. And
65+
the user will have an impression that the submit didn't work.
66+
"""
667

768

869
setup(
@@ -26,6 +87,6 @@
2687
'Programming Language :: Python :: 2.6',
2788
'Programming Language :: Python :: 2.7',
2889
],
29-
version='1.0',
90+
version='1.1',
3091
py_modules=['flask_replicated'],
3192
)

0 commit comments

Comments
 (0)