Skip to content

Commit 6bbbc1b

Browse files
author
Petr
committed
update setup.py
convert README to rst, add badge
1 parent d7a8942 commit 6bbbc1b

File tree

3 files changed

+68
-119
lines changed

3 files changed

+68
-119
lines changed

README.md

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

README.rst

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

setup.py

Lines changed: 6 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,8 @@
11
from setuptools import setup
22

33

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-
"""
4+
with open('README.rst') as fp:
5+
readme = fp.read()
676

687

698
setup(
@@ -86,6 +25,10 @@
8625
'Programming Language :: Python :: 2',
8726
'Programming Language :: Python :: 2.6',
8827
'Programming Language :: Python :: 2.7',
28+
'Programming Language :: Python :: 3',
29+
'Programming Language :: Python :: 3.5',
30+
'Programming Language :: Python :: 3.6',
31+
'Programming Language :: Python :: 3.7',
8932
],
9033
version='1.3',
9134
py_modules=['flask_replicated'],

0 commit comments

Comments
 (0)