1639249200
Simple CLI that provides the following commands:
flask psql create
flask psql init
flask psql drop
flask psql setup
: create → initflask psql reset
: drop → create → initThese commands are available out of the box as long as you’re using Flask-SQLAlchemy. Flask-Postgres finds your db
instance for you, so it knows exactly how to create, initialize, and delete your database.
pip install flask-postgres
and you’re ready to go!The below example shows an app with a custom init_db_callback
, which is optional.
# app.py
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_postgres import init_db_callback
app = Flask(__name__)
app.config["SQLALCHEMY_DATABASE_URI"] = "postgresql://localhost:5432/example"
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
db = SQLAlchemy(app)
class Pet(db.Model):
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
name = db.Column(db.Text)
@init_db_callback
def init_db(app, db):
db.create_all()
# Add your first pet
pet = Pet(name="Fido")
db.session.add(pet)
db.session.commit()
Now run in your terminal:
flask psql setup
And you’ll have a Postgres database up and running with the initialized data.
Want to make a change, and don’t mind starting everything over? Then run:
flask psql reset
pip install flask-postgres
Once you have installed Flask-Postgres, you should be ready to go assuming your code is already set up to use Flask-SQLAlchemy
. Check that the commands are available here:
flask psql --help
init
CallbackFlask-Postgres does not require any more setup than this, unless you want to add a custom callback that runs when psql init
is executed. The callback can take app
and/or db
args, or the function signature can be left blank:
from flask_postgres import init_db_callback
@init_db_callback
def init_db(app, db):
db.create_all()
# alternatively...
@init_db_callback
def init_db(app):
...
# alternatively...
@init_db_callback
def init_db(db):
...
# alternatively...
@init_db_callback
def init_db():
...
Note that your init_db_callback
will be run inside the application context.
By default, if you do not register a callback, then Flask-Postgres will run db.create_all()
for you when initializing the database. So if all you need is db.create_all()
, then you can let Flask-Postgres take care of it.
For apps already setup to use Flask-SQLALchemy, all Flask-Postgres configuration is optional, and probably is not necessary for most users.
Name | Type | Description |
---|---|---|
FLASK_POSTGRES_CLI_DISALLOWED_ENVS | Sequence[str] (or str delimited by ; ) | List of environments where the
(Default behavior is the CLI is never disabled.) |
FLASK_POSTGRES_TARGET_DATABASE_URI | str | URL for the Postgres database to be created / initialized / deleted.
(Default behavior is to use |
FLASK_POSTGRES_ADMIN_DBNAME | str | Database name to use when connecting to the Postgres server to create or delete another database.
It’s not recomended that you mess around with this unless you need to. (Default behavior is to replace |
By default, Flask-Postgres uses the SQLALCHEMY_DATABASE_URI
as the database to be created / initialized / deleted. Flask-Postgres replaces the {dbname}
in the URI with postgres
to handle database administration.
FLASK_POSTGRES_TARGET_DATABASE_URI
.-d postgres
, then set the FLASK_POSTGRES_ADMIN_DBNAME
.By default, flask psql
can be run in any environment. If you want to restrict access to flask psql
based on the FLASK_ENV
, then you can set the config variable FLASK_POSTGRES_CLI_DISALLOWED_ENVS
, which is a sequence of strings.
For example, if you don’t want flask psql
to run in production:
app.config["FLASK_POSTGRES_CLI_DISALLOWED_ENVS"] = ["production"]
This is not protection against malicious use– anyone with access to a terminal in your production environment can do whatever they want. It is good enough protection against mistakes, though.
You can access all of the above config variables (including SQLALCHEMY_DATABASE_URI
) through environment variables.
Flask-Postgres always prefers Flask app config variables to equivalently named environment variables. Additionally, Flask-Postgres always prefers FLASK_POSTGRES_*
prefixed variables to using SQLALCHEMY_DATABASE_URI
.
For example, if your environment variable is SQLALCHEMY_DATABASE_URI=foo
, and your Flask app config variable is FLASK_POSTGRES_TARGET_DATABASE_URI=bar
, then Flask-Postgres will use bar
.
CLI options always override everything.
This package is useful if:
Which is to say, this package is a lightweight alternative to setting up an application in a fully fledged production way.
For serious production stuff, look into Docker Compose (to create
your database) and Alembic (to init
your database).
0.2.0
: Broke the API in a few spots and made it more consistent.dbname
is the commonly used variable name.create_db
and drop_db
.--force-disconnect
and --overwrite
.PostgresUri
. This builds and validates a Postgres URI, and provides helpful information to the user on why it’s invalid. This is used both internally to make the code nicer + safer, and it’s also as a click.ParamType
.0.1.4
: First real release.Author: dwreeves
Source code: https://github.com/dwreeves/Flask-Postgres
License: MIT License
1639249200
Simple CLI that provides the following commands:
flask psql create
flask psql init
flask psql drop
flask psql setup
: create → initflask psql reset
: drop → create → initThese commands are available out of the box as long as you’re using Flask-SQLAlchemy. Flask-Postgres finds your db
instance for you, so it knows exactly how to create, initialize, and delete your database.
pip install flask-postgres
and you’re ready to go!The below example shows an app with a custom init_db_callback
, which is optional.
# app.py
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_postgres import init_db_callback
app = Flask(__name__)
app.config["SQLALCHEMY_DATABASE_URI"] = "postgresql://localhost:5432/example"
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
db = SQLAlchemy(app)
class Pet(db.Model):
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
name = db.Column(db.Text)
@init_db_callback
def init_db(app, db):
db.create_all()
# Add your first pet
pet = Pet(name="Fido")
db.session.add(pet)
db.session.commit()
Now run in your terminal:
flask psql setup
And you’ll have a Postgres database up and running with the initialized data.
Want to make a change, and don’t mind starting everything over? Then run:
flask psql reset
pip install flask-postgres
Once you have installed Flask-Postgres, you should be ready to go assuming your code is already set up to use Flask-SQLAlchemy
. Check that the commands are available here:
flask psql --help
init
CallbackFlask-Postgres does not require any more setup than this, unless you want to add a custom callback that runs when psql init
is executed. The callback can take app
and/or db
args, or the function signature can be left blank:
from flask_postgres import init_db_callback
@init_db_callback
def init_db(app, db):
db.create_all()
# alternatively...
@init_db_callback
def init_db(app):
...
# alternatively...
@init_db_callback
def init_db(db):
...
# alternatively...
@init_db_callback
def init_db():
...
Note that your init_db_callback
will be run inside the application context.
By default, if you do not register a callback, then Flask-Postgres will run db.create_all()
for you when initializing the database. So if all you need is db.create_all()
, then you can let Flask-Postgres take care of it.
For apps already setup to use Flask-SQLALchemy, all Flask-Postgres configuration is optional, and probably is not necessary for most users.
Name | Type | Description |
---|---|---|
FLASK_POSTGRES_CLI_DISALLOWED_ENVS | Sequence[str] (or str delimited by ; ) | List of environments where the
(Default behavior is the CLI is never disabled.) |
FLASK_POSTGRES_TARGET_DATABASE_URI | str | URL for the Postgres database to be created / initialized / deleted.
(Default behavior is to use |
FLASK_POSTGRES_ADMIN_DBNAME | str | Database name to use when connecting to the Postgres server to create or delete another database.
It’s not recomended that you mess around with this unless you need to. (Default behavior is to replace |
By default, Flask-Postgres uses the SQLALCHEMY_DATABASE_URI
as the database to be created / initialized / deleted. Flask-Postgres replaces the {dbname}
in the URI with postgres
to handle database administration.
FLASK_POSTGRES_TARGET_DATABASE_URI
.-d postgres
, then set the FLASK_POSTGRES_ADMIN_DBNAME
.By default, flask psql
can be run in any environment. If you want to restrict access to flask psql
based on the FLASK_ENV
, then you can set the config variable FLASK_POSTGRES_CLI_DISALLOWED_ENVS
, which is a sequence of strings.
For example, if you don’t want flask psql
to run in production:
app.config["FLASK_POSTGRES_CLI_DISALLOWED_ENVS"] = ["production"]
This is not protection against malicious use– anyone with access to a terminal in your production environment can do whatever they want. It is good enough protection against mistakes, though.
You can access all of the above config variables (including SQLALCHEMY_DATABASE_URI
) through environment variables.
Flask-Postgres always prefers Flask app config variables to equivalently named environment variables. Additionally, Flask-Postgres always prefers FLASK_POSTGRES_*
prefixed variables to using SQLALCHEMY_DATABASE_URI
.
For example, if your environment variable is SQLALCHEMY_DATABASE_URI=foo
, and your Flask app config variable is FLASK_POSTGRES_TARGET_DATABASE_URI=bar
, then Flask-Postgres will use bar
.
CLI options always override everything.
This package is useful if:
Which is to say, this package is a lightweight alternative to setting up an application in a fully fledged production way.
For serious production stuff, look into Docker Compose (to create
your database) and Alembic (to init
your database).
0.2.0
: Broke the API in a few spots and made it more consistent.dbname
is the commonly used variable name.create_db
and drop_db
.--force-disconnect
and --overwrite
.PostgresUri
. This builds and validates a Postgres URI, and provides helpful information to the user on why it’s invalid. This is used both internally to make the code nicer + safer, and it’s also as a click.ParamType
.0.1.4
: First real release.Author: dwreeves
Source code: https://github.com/dwreeves/Flask-Postgres
License: MIT License
1640257440
A simple Boilerplate to Setup Authentication using Django-allauth, with a custom template for login and registration using django-crispy-forms
.
# clone the repo
$ git clone https://github.com/yezz123/Django-Authentication
# move to the project folder
$ cd Django-Authentication
virtual environment
for this project:# creating pipenv environment for python 3
$ virtualenv venv
# activating the pipenv environment
$ cd venv/bin #windows environment you activate from Scripts folder
# if you have multiple python 3 versions installed then
$ source ./activate
SECRET_KEY = #random string
DEBUG = #True or False
ALLOWED_HOSTS = #localhost
DATABASE_NAME = #database name (You can just use the default if you want to use SQLite)
DATABASE_USER = #database user for postgres
DATABASE_PASSWORD = #database password for postgres
DATABASE_HOST = #database host for postgres
DATABASE_PORT = #database port for postgres
ACCOUNT_EMAIL_VERIFICATION = #mandatory or optional
EMAIL_BACKEND = #email backend
EMAIL_HOST = #email host
EMAIL_HOST_PASSWORD = #email host password
EMAIL_USE_TLS = # if your email use tls
EMAIL_PORT = #email port
change all the environment variables in the
.env.sample
and don't forget to rename it to.env
.
After Setup the environment, you can run the project using the Makefile
provided in the project folder.
help:
@echo "Targets:"
@echo " make install" #install requirements
@echo " make makemigrations" #prepare migrations
@echo " make migrations" #migrate database
@echo " make createsuperuser" #create superuser
@echo " make run_server" #run the server
@echo " make lint" #lint the code using black
@echo " make test" #run the tests using Pytest
Includes preconfigured packages to kick start Django-Authentication by just setting appropriate configuration.
Package | Usage |
---|---|
django-allauth | Integrated set of Django applications addressing authentication, registration, account management as well as 3rd party (social) account authentication. |
django-crispy-forms | django-crispy-forms provides you with a crispy filter and {% crispy %} tag that will let you control the rendering behavior of your Django forms in a very elegant and DRY way. |
Download Details:
Author: yezz123
Source Code: https://github.com/yezz123/Django-Authentication
License: MIT License
1620640920
Finding the right database solution for your application is not easy. At iQIYI, one of the largest online video sites in the world, we’re experienced in database selection across several fields: Online Transactional Processing (OLTP), Online Analytical Processing (OLAP), Hybrid Transaction/Analytical Processing (HTAP), SQL, and NoSQL.
Today, I’ll share with you:
I hope this post can help you easily find the right database for your applications.
#database architecture #database application #database choice #database management system #database management tool
1625133780
The pandemic has brought a period of transformation across businesses globally, pushing data and analytics to the forefront of decision making. Starting from enabling advanced data-driven operations to creating intelligent workflows, enterprise leaders have been looking to transform every part of their organisation.
SingleStore is one of the leading companies in the world, offering a unified database to facilitate fast analytics for organisations looking to embrace diverse data and accelerate their innovations. It provides an SQL platform to help companies aggregate, manage, and use the vast trove of data distributed across silos in multiple clouds and on-premise environments.
**Your expertise needed! **Fill up our quick Survey
#featured #data analytics #data warehouse augmentation #database #database management #fast analytics #memsql #modern database #modernising data platforms #one stop shop for data #singlestore #singlestore data analytics #singlestore database #singlestore one stop shop for data #singlestore unified database #sql #sql database
1620633584
In SSMS, we many of may noticed System Databases under the Database Folder. But how many of us knows its purpose?. In this article lets discuss about the System Databases in SQL Server.
Fig. 1 System Databases
There are five system databases, these databases are created while installing SQL Server.
#sql server #master system database #model system database #msdb system database #sql server system databases #ssms #system database #system databases in sql server #tempdb system database