*Flaskez* is a multipurpose flask extension. It exists both to make creating websites easier, but also to add extra functionality to flask.
Installation:
-
```shell
pip install flaskez
```
Import as:
-
```python
import flaskez
```
Example program:
-
```python
import flaskez
app = flaskez.create_app(__name__)
@app.route("/")
def home():
return "Hello!"
```
In this example, the syntax and everything is exactly like flask. The bigger help comes in to play when you are writing more complex programs.
---
Example 2:
---
```python
import flaskez
app, db = flaskez.create_app(
__name__,
config={
"SQLALCHEMY_DATABASE_URI": "sqlite:///users.sqlite3",
"SQLALCHEMY_TRACK_MODIFICATIONS": False
},
create_db=True
)
@app.route("/")
def home():
return "Hello!"
if __name__ == '__main__':
app.run()
```
This program generates an SQLAlchemy database using [flask-SQLAlchemy](https://pypi.org/project/flask-sqlalchemy/).
In this current example the database is not used.
I am currently working on making an importable universal database model.
The config dictionary sets ``app.config["SQLALCHEMY_DATABASE_URI"]`` to ``"sqlite:///users.sqlite3"``, and ``app.config["SQLALCHEMY_TRACK_MODIFICATIONS"]`` to ``False``.
It also tells the function that we should create a database.
Depending on if create_db is true or not, the program either returns a flask.Flask object, or a tuple with flask.Flask and SQLAlchemy.
By default, the application generates a secret key using:
```python
app.secret_key = str(
time.time()) + str(
random.randrange(1, 10000)) + str(
secrets.randbelow(100000) * random.randrange(1, 100)) + str(
secrets.randbelow(1000000000) * 0.0001 * time.time())
```
This can be disabled by settings ``generate_secret_key`` to ``False``:
```python
import flaskez
app, db = flaskez.create_app(
__name__,
config={
"SQLALCHEMY_DATABASE_URI": "sqlite:///users.sqlite3",
"SQLALCHEMY_TRACK_MODIFICATIONS": False
},
generate_secret_key=False,
create_db=True
)
```
This will set the secret key to ``"DefaultKey"``, but can be changed using ``secret_key="my_secret_key"``.
---
Example 3:
---
The ``create_app()`` function has a parameter called run, which you can use to run the flask.Flask object directly from the function.
This requires having defined blueprints beforehand.
```python
import flaskez
from flask import Blueprint
routes = Blueprint('routes', __name__) # Can be placed inside another file and then imported
@routes.route("/")
def home():
return "Hello!"
app = flaskez.create_app(
__name__,
run=True,
routes=[
{
'blueprint': routes
}
]
)
```
---
**All the parameters for flaskez.create_app() are:**
* app_name: Name of the Flask application. Usually \_\_name__ works just fine.
* *args: Optional positional arguments. Passed to the flask.Flask().register_blueprint() function.
* run: Optional bool if you want the function to run the application directly.
* run_kwargs: Optional dict if you want extra keyword arguments passed to the flask.Flask().run() function.
* config: Dictionary. Configuration for the flask.Flask object.
* secret_key: String. Variable if you want to define a custom secret key for the application.
* generate_secret_key: Bool. Variable if you want to generate a secret key. Uses python's random and secrets modules.
* routes: List. A list with dictionaries of all blueprints for the application. Format: routes=[{'path': 'routes.routes', 'blueprint': 'routes'}] or routes=[{'blueprint': flask.Blueprint(*args, **kwargs)}] Path can also be the imported file. An optional key 'prefix' can be added to specify a prefix for the url (an extra / (route) before the unique route of the web page). It is easier to use the create_blueprint() function (see its docs for more info).
* error_pages: List. A list with dictionaries of all error pages for the application. Format: error_pages=[{'path': 'routes.routes', 'code': '404', 'function': 'not_found'}]
* permanent_session_lifetime: Dictionary. Permanent session lifetime variable for flask.sessions.
* create_db: Bool. Optionally create a database (using flask-sqlalchemy). Used for login, etc.
* flask_kwargs: A dictionary for arguments passed to the creation of the flask.Flask object (kwargs and args are already used for blueprints)
* db_kwargs: A dictionary for arguments passed to the creation of the flask_sqlalchemy.SQLAlchemy object (kwargs and args are already used for blueprints)
* **kwargs: Optional keyword arguments. Passed to the register_blueprint() function.
---
### For more functionality, visit the [GitHub](https://github.com/IHasBone/flaskez).
# Changelog
### 0.2.0 (01/12/2022)
* Fixed up a lot of smaller bugs in the code, and fixed the warnings not making any sense.
### 0.1.2 (01/12/2022)
* Made _basic and _models subpackages since normal directories don't get uploaded.
### 0.1.1 (01/12/2022)
* Added *.md in global-include because I forgot to...
### 0.1.0 (01/12/2022)
* First Release
Raw data
{
"_id": null,
"home_page": "https://github.com/IHasBone/flaskez",
"name": "flaskez",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "flask,extension,website,web,site,flask-sqlalchemy,database,sqlalchemy",
"author": "IHasBone",
"author_email": "info@picstreme.com",
"download_url": "https://files.pythonhosted.org/packages/7e/7b/046a1d91a2671f4f11c3c0a4a7381f3c9e8fe9f57ed3bfbe0a3399334d60/flaskez-0.2.0.tar.gz",
"platform": null,
"description": "*Flaskez* is a multipurpose flask extension. It exists both to make creating websites easier, but also to add extra functionality to flask.\r\n\r\nInstallation:\r\n-\r\n```shell\r\npip install flaskez\r\n```\r\n\r\nImport as:\r\n-\r\n```python\r\nimport flaskez\r\n```\r\n\r\nExample program:\r\n-\r\n```python\r\nimport flaskez\r\n\r\napp = flaskez.create_app(__name__)\r\n\r\n@app.route(\"/\")\r\ndef home():\r\n return \"Hello!\"\r\n```\r\nIn this example, the syntax and everything is exactly like flask. The bigger help comes in to play when you are writing more complex programs.\r\n\r\n---\r\nExample 2:\r\n---\r\n```python\r\nimport flaskez\r\n\r\napp, db = flaskez.create_app(\r\n __name__,\r\n config={\r\n \"SQLALCHEMY_DATABASE_URI\": \"sqlite:///users.sqlite3\",\r\n \"SQLALCHEMY_TRACK_MODIFICATIONS\": False\r\n },\r\n create_db=True\r\n)\r\n\r\n@app.route(\"/\")\r\ndef home():\r\n return \"Hello!\"\r\n\r\nif __name__ == '__main__':\r\n app.run()\r\n```\r\nThis program generates an SQLAlchemy database using [flask-SQLAlchemy](https://pypi.org/project/flask-sqlalchemy/).\r\nIn this current example the database is not used.\r\nI am currently working on making an importable universal database model.\r\nThe config dictionary sets ``app.config[\"SQLALCHEMY_DATABASE_URI\"]`` to ``\"sqlite:///users.sqlite3\"``, and ``app.config[\"SQLALCHEMY_TRACK_MODIFICATIONS\"]`` to ``False``.\r\nIt also tells the function that we should create a database.\r\nDepending on if create_db is true or not, the program either returns a flask.Flask object, or a tuple with flask.Flask and SQLAlchemy.\r\n\r\nBy default, the application generates a secret key using:\r\n```python\r\napp.secret_key = str(\r\n time.time()) + str(\r\n random.randrange(1, 10000)) + str(\r\n secrets.randbelow(100000) * random.randrange(1, 100)) + str(\r\n secrets.randbelow(1000000000) * 0.0001 * time.time())\r\n```\r\nThis can be disabled by settings ``generate_secret_key`` to ``False``:\r\n```python\r\nimport flaskez\r\n\r\napp, db = flaskez.create_app(\r\n __name__,\r\n config={\r\n \"SQLALCHEMY_DATABASE_URI\": \"sqlite:///users.sqlite3\",\r\n \"SQLALCHEMY_TRACK_MODIFICATIONS\": False\r\n },\r\n generate_secret_key=False,\r\n create_db=True\r\n)\r\n```\r\nThis will set the secret key to ``\"DefaultKey\"``, but can be changed using ``secret_key=\"my_secret_key\"``.\r\n\r\n---\r\nExample 3:\r\n---\r\nThe ``create_app()`` function has a parameter called run, which you can use to run the flask.Flask object directly from the function.\r\nThis requires having defined blueprints beforehand.\r\n```python\r\nimport flaskez\r\nfrom flask import Blueprint\r\n\r\nroutes = Blueprint('routes', __name__) # Can be placed inside another file and then imported\r\n\r\n@routes.route(\"/\")\r\ndef home():\r\n return \"Hello!\"\r\n\r\napp = flaskez.create_app(\r\n __name__,\r\n run=True,\r\n routes=[\r\n {\r\n 'blueprint': routes\r\n }\r\n ]\r\n)\r\n```\r\n---\r\n**All the parameters for flaskez.create_app() are:**\r\n* app_name: Name of the Flask application. Usually \\_\\_name__ works just fine.\r\n* *args: Optional positional arguments. Passed to the flask.Flask().register_blueprint() function.\r\n* run: Optional bool if you want the function to run the application directly.\r\n* run_kwargs: Optional dict if you want extra keyword arguments passed to the flask.Flask().run() function.\r\n* config: Dictionary. Configuration for the flask.Flask object.\r\n* secret_key: String. Variable if you want to define a custom secret key for the application.\r\n* generate_secret_key: Bool. Variable if you want to generate a secret key. Uses python's random and secrets modules.\r\n* routes: List. A list with dictionaries of all blueprints for the application. Format: routes=[{'path': 'routes.routes', 'blueprint': 'routes'}] or routes=[{'blueprint': flask.Blueprint(*args, **kwargs)}] Path can also be the imported file. An optional key 'prefix' can be added to specify a prefix for the url (an extra / (route) before the unique route of the web page). It is easier to use the create_blueprint() function (see its docs for more info).\r\n* error_pages: List. A list with dictionaries of all error pages for the application. Format: error_pages=[{'path': 'routes.routes', 'code': '404', 'function': 'not_found'}]\r\n* permanent_session_lifetime: Dictionary. Permanent session lifetime variable for flask.sessions.\r\n* create_db: Bool. Optionally create a database (using flask-sqlalchemy). Used for login, etc.\r\n* flask_kwargs: A dictionary for arguments passed to the creation of the flask.Flask object (kwargs and args are already used for blueprints)\r\n* db_kwargs: A dictionary for arguments passed to the creation of the flask_sqlalchemy.SQLAlchemy object (kwargs and args are already used for blueprints)\r\n* **kwargs: Optional keyword arguments. Passed to the register_blueprint() function.\r\n---\r\n### For more functionality, visit the [GitHub](https://github.com/IHasBone/flaskez).\r\n\r\n\r\n# Changelog\r\n\r\n\r\n### 0.2.0 (01/12/2022)\r\n* Fixed up a lot of smaller bugs in the code, and fixed the warnings not making any sense.\r\n\r\n\r\n### 0.1.2 (01/12/2022)\r\n* Made _basic and _models subpackages since normal directories don't get uploaded.\r\n\r\n\r\n### 0.1.1 (01/12/2022)\r\n* Added *.md in global-include because I forgot to...\r\n\r\n\r\n### 0.1.0 (01/12/2022)\r\n* First Release\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Flaskez is a multipurpose flask extension. It exists both to make creating websites easier, but also to add extra functionality to flask.",
"version": "0.2.0",
"split_keywords": [
"flask",
"extension",
"website",
"web",
"site",
"flask-sqlalchemy",
"database",
"sqlalchemy"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "7e7b046a1d91a2671f4f11c3c0a4a7381f3c9e8fe9f57ed3bfbe0a3399334d60",
"md5": "e55a292469fcea24e16bd720d84c7aac",
"sha256": "d760d310e506b3842fe39adcead35a3a1678cb10c9646e3b78973bdfaff6fdb0"
},
"downloads": -1,
"filename": "flaskez-0.2.0.tar.gz",
"has_sig": false,
"md5_digest": "e55a292469fcea24e16bd720d84c7aac",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 9266,
"upload_time": "2022-12-01T16:00:53",
"upload_time_iso_8601": "2022-12-01T16:00:53.839050Z",
"url": "https://files.pythonhosted.org/packages/7e/7b/046a1d91a2671f4f11c3c0a4a7381f3c9e8fe9f57ed3bfbe0a3399334d60/flaskez-0.2.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2022-12-01 16:00:53",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "IHasBone",
"github_project": "flaskez",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "flaskez"
}