# NLDCSC package
[![GitHub Release](https://img.shields.io/github/release/NLDCSC/nldcsc.svg?style=flat)]()
[![GPLv3 License](https://img.shields.io/badge/License-GPL%20v3-yellow.svg)](https://opensource.org/licenses/)
[![codecov](https://codecov.io/gh/NLDCSC/nldcsc/graph/badge.svg?token=QSHW4B6ADR)](https://codecov.io/gh/NLDCSC/nldcsc)
![pypi](https://github.com/NLDCSC/nldcsc/actions/workflows/package_to_pypi.yaml/badge.svg)
![pytest](https://github.com/NLDCSC/nldcsc/actions/workflows/tox_tests.yaml/badge.svg)
This package contains generic re-usable code.
Install the full package:
```
pip install nldcsc[all]
```
Package has several modules which can be installed separately by specifying them
as an extra requirement. To install the loggers module only, specify:
```
pip install nldcsc[loggers]
```
Or for multiple modules:
```
pip install nldcsc[loggers, flask_managers]
```
## Modules
The following modules are available in the nldcsc package:
* auth
* datatables
* flask_managers
* flask_middleware
* flask_plugins
* http_apis
* httpx_apis
* loggers
* sql_migrations
* sso
* plugins
- plugin_doh
- plugin_geo_ip
- plugin_sql_migrate
- plugin_redis
* custom_types
- custom_type_sqlalchemy
### Loggers
There are two loggers provided:
* AppLogger (nldcsc.loggers.app_logger.AppLogger)
* GunicornLogger (nldcsc.loggers.app_logger.GunicornLogger)
The AppLogger is intended to be used as a loggerClass to be used for the
standard python logging module.
```python
import logging
from nldcsc.loggers.app_logger import AppLogger
logging.setLoggerClass(AppLogger)
mylogger = logging.getLogger(__name__)
```
The 'mylogger' instance has all the proper formatting and handlers
(according to the desired config) to log messages.
The Gunicorn logger is intended to be used for as a loggerClass for the
gunicorn webserver; it enables the FlaskAppManager to set the necessary
formatting and handles according to the AppLogger specs and a custom format
for the gunicorn access logging.
### Flask app manager
The FlaskAppManager is intended to be used to 'run' flask applications in
both test, development as in production environments.
```python
from YADA import app
from nldcsc.flask_managers.flask_app_manager import FlaskAppManager
fam = FlaskAppManager(version="1.0", app=app)
fam.run()
```
Depending on the configuration the FlaskAppManager uses a werkzeug (DEBUG == True)
or a gunicorn webserver. TLS could be set for both webservers iaw the module specific
README.md.
### HTTP apis
Baseclass for http api communication is present under
nldcsc.http_apis.base_class.api_base_class.ApiBaseClass
### HTTPX apis
Baseclass for httpx api communication is present under
nldcsc.httpx_apis.base_class.httpx_base_class.HTTPXBaseClass
### SQL Migrations
The sql migrations can be used to facilitate migration between different
versions of sql models / versions. It relies on flask migrate to perform
the different migrations. It has a CLI as well as an python class based API.
Check the command line help
```
python3 -m nldcsc.sql_migrations.flask_sql_migrate -a /path/to/script_with_flask_app.py -i
python3 -m nldcsc.sql_migrations.flask_sql_migrate -a /path/to/script_with_flask_app.py -m
python3 -m nldcsc.sql_migrations.flask_sql_migrate -a /path/to/script_with_flask_app.py -u
```
Or initiate the FlaskSqlMigrate as a class and initiate the migration
process from there:
```python
from nldcsc.sql_migrations.flask_sql_migrate import FlaskSqlMigrate
fsm = FlaskSqlMigrate(app_ref="/path/to/script_with_flask_app.py")
fsm.db_init()
fsm.db_migrate()
fsm.db_update()
```
### Plugins
There are several off the shelf plugins that can be used in other projects. Every plugin can be installed with:
```
pip install nldcsc[plugin-<plugin-name>]
```
or if you rather install all the plugins:
```
pip install nldcsc[plugins]
```
#### plugin-sql-migrate
The sql_migrate plugin serves as a wrapper around alembic but replaces the naming convention of migration files to support multiple branches of development. To make use of this plugin the CLI can be used.
Check the command line help
```
python3 -m nldcsc db --help
```
OR
```
nldcsc db --help
```
The plugin expects to be pointed towards a python configuration file that looks something like this:
```python
from my_awesome_project.db import get_engine
from my_awesome_project.models.base import ModelBase
#This should be a SQLAlchemy engine object.
db = get_engine()
#This should be the modelbase class metadata
metadata = ModelBase.metadata
```
### Custom types
Custom types is a collection of custom types or objects that can be used with other libraries
#### custom_type_sqlalchemy
This is a collection of types to be used together with sqlalchemy. If these types are to be used make sure to inherit from the ModelBase within the NLDCSC package. As the types get mapped to their SQL equivalents there.
## Adding modules and/or groups
Everything for this package is defined in the pyproject.toml file. Dependencies are managed by poetry and grouped in, you guessed it, groups. Every poetry group can be installed as an extra using pip.
Extra extras or group on group/extra dependencies can also be defined in the [tool.nldcsc.group.dependencies] section. Everything defined here will also become an extra if no group already exists. You can use everything defined here as dependency for another group, order does **not** matter.
example:
```toml
[tool.nldcsc.group.dependencies]
my_awesome_extra = ["my_awesome_group", "my_other_group"]
my_awesome_group = ["my_logging_group"]
[tool.poetry.group.my_awesome_group.dependencies]
<dependency here>
[tool.poetry.group.my_other_group.dependencies]
<dependency here>
[tool.poetry.group.my_logging_group.dependencies]
<dependency here>
```
Using this example the following extras exist with the correct dependencies:
```
pip install nldcsc[all]
pip install nldcsc[my-awesome-extra]
pip install nldcsc[my-awesome-group]
pip install nldcsc[my-other-group]
pip install nldcsc[my-logging-group]
```
Raw data
{
"_id": null,
"home_page": "https://github.com/NLDCSC/nldcsc",
"name": "nldcsc",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.10",
"maintainer_email": null,
"keywords": null,
"author": "NLDCSC",
"author_email": "NLDCSC@invalid.com",
"download_url": "https://files.pythonhosted.org/packages/8e/3d/34b1e8d4570951ba60cc3e736d8b0228c12033c00e52ee94efb435092202/nldcsc-0.3.12.tar.gz",
"platform": "any",
"description": "# NLDCSC package\n\n[![GitHub Release](https://img.shields.io/github/release/NLDCSC/nldcsc.svg?style=flat)]()\n[![GPLv3 License](https://img.shields.io/badge/License-GPL%20v3-yellow.svg)](https://opensource.org/licenses/)\n\n[![codecov](https://codecov.io/gh/NLDCSC/nldcsc/graph/badge.svg?token=QSHW4B6ADR)](https://codecov.io/gh/NLDCSC/nldcsc)\n![pypi](https://github.com/NLDCSC/nldcsc/actions/workflows/package_to_pypi.yaml/badge.svg)\n![pytest](https://github.com/NLDCSC/nldcsc/actions/workflows/tox_tests.yaml/badge.svg)\n\nThis package contains generic re-usable code.\n\nInstall the full package:\n\n```\npip install nldcsc[all]\n```\n\nPackage has several modules which can be installed separately by specifying them \nas an extra requirement. To install the loggers module only, specify:\n\n```\npip install nldcsc[loggers]\n```\nOr for multiple modules:\n```\npip install nldcsc[loggers, flask_managers]\n```\n\n## Modules\n\nThe following modules are available in the nldcsc package:\n\n* auth\n* datatables\n* flask_managers\n* flask_middleware\n* flask_plugins\n* http_apis\n* httpx_apis\n* loggers\n* sql_migrations\n* sso\n* plugins\n - plugin_doh\n - plugin_geo_ip\n - plugin_sql_migrate\n - plugin_redis\n* custom_types\n - custom_type_sqlalchemy\n\n### Loggers\n\nThere are two loggers provided:\n* AppLogger (nldcsc.loggers.app_logger.AppLogger)\n* GunicornLogger (nldcsc.loggers.app_logger.GunicornLogger)\n\nThe AppLogger is intended to be used as a loggerClass to be used for the \nstandard python logging module.\n\n```python\nimport logging\nfrom nldcsc.loggers.app_logger import AppLogger\n\nlogging.setLoggerClass(AppLogger)\n\nmylogger = logging.getLogger(__name__)\n```\nThe 'mylogger' instance has all the proper formatting and handlers \n(according to the desired config) to log messages.\n\nThe Gunicorn logger is intended to be used for as a loggerClass for the \ngunicorn webserver; it enables the FlaskAppManager to set the necessary \nformatting and handles according to the AppLogger specs and a custom format\nfor the gunicorn access logging.\n\n### Flask app manager\n\nThe FlaskAppManager is intended to be used to 'run' flask applications in \nboth test, development as in production environments. \n\n```python\nfrom YADA import app\nfrom nldcsc.flask_managers.flask_app_manager import FlaskAppManager\n\nfam = FlaskAppManager(version=\"1.0\", app=app)\nfam.run()\n```\nDepending on the configuration the FlaskAppManager uses a werkzeug (DEBUG == True)\nor a gunicorn webserver. TLS could be set for both webservers iaw the module specific\nREADME.md.\n\n### HTTP apis\n\nBaseclass for http api communication is present under \nnldcsc.http_apis.base_class.api_base_class.ApiBaseClass\n\n### HTTPX apis\n\nBaseclass for httpx api communication is present under \nnldcsc.httpx_apis.base_class.httpx_base_class.HTTPXBaseClass\n\n### SQL Migrations\n\nThe sql migrations can be used to facilitate migration between different\nversions of sql models / versions. It relies on flask migrate to perform\nthe different migrations. It has a CLI as well as an python class based API.\n\nCheck the command line help\n```\npython3 -m nldcsc.sql_migrations.flask_sql_migrate -a /path/to/script_with_flask_app.py -i\npython3 -m nldcsc.sql_migrations.flask_sql_migrate -a /path/to/script_with_flask_app.py -m\npython3 -m nldcsc.sql_migrations.flask_sql_migrate -a /path/to/script_with_flask_app.py -u\n```\n\nOr initiate the FlaskSqlMigrate as a class and initiate the migration \nprocess from there: \n```python\nfrom nldcsc.sql_migrations.flask_sql_migrate import FlaskSqlMigrate\nfsm = FlaskSqlMigrate(app_ref=\"/path/to/script_with_flask_app.py\")\n\nfsm.db_init()\nfsm.db_migrate()\nfsm.db_update()\n```\n\n### Plugins\n\nThere are several off the shelf plugins that can be used in other projects. Every plugin can be installed with:\n```\npip install nldcsc[plugin-<plugin-name>]\n```\nor if you rather install all the plugins:\n```\npip install nldcsc[plugins]\n```\n\n#### plugin-sql-migrate\n\nThe sql_migrate plugin serves as a wrapper around alembic but replaces the naming convention of migration files to support multiple branches of development. To make use of this plugin the CLI can be used.\n\nCheck the command line help\n```\npython3 -m nldcsc db --help\n```\nOR\n```\nnldcsc db --help\n```\n\nThe plugin expects to be pointed towards a python configuration file that looks something like this:\n```python\nfrom my_awesome_project.db import get_engine\nfrom my_awesome_project.models.base import ModelBase\n\n#This should be a SQLAlchemy engine object.\ndb = get_engine()\n\n#This should be the modelbase class metadata\nmetadata = ModelBase.metadata\n```\n\n### Custom types\n\nCustom types is a collection of custom types or objects that can be used with other libraries\n\n#### custom_type_sqlalchemy\n\nThis is a collection of types to be used together with sqlalchemy. If these types are to be used make sure to inherit from the ModelBase within the NLDCSC package. As the types get mapped to their SQL equivalents there.\n\n## Adding modules and/or groups\n\nEverything for this package is defined in the pyproject.toml file. Dependencies are managed by poetry and grouped in, you guessed it, groups. Every poetry group can be installed as an extra using pip. \n\nExtra extras or group on group/extra dependencies can also be defined in the [tool.nldcsc.group.dependencies] section. Everything defined here will also become an extra if no group already exists. You can use everything defined here as dependency for another group, order does **not** matter.\n\nexample:\n```toml\n[tool.nldcsc.group.dependencies]\nmy_awesome_extra = [\"my_awesome_group\", \"my_other_group\"]\nmy_awesome_group = [\"my_logging_group\"]\n\n[tool.poetry.group.my_awesome_group.dependencies]\n<dependency here>\n\n[tool.poetry.group.my_other_group.dependencies]\n<dependency here>\n\n[tool.poetry.group.my_logging_group.dependencies]\n<dependency here>\n```\n\nUsing this example the following extras exist with the correct dependencies:\n```\npip install nldcsc[all]\npip install nldcsc[my-awesome-extra]\npip install nldcsc[my-awesome-group]\npip install nldcsc[my-other-group]\npip install nldcsc[my-logging-group]\n```\n",
"bugtrack_url": null,
"license": "GNU General Public License v3.0",
"summary": "Package with general devops code",
"version": "0.3.12",
"project_urls": {
"Code": "https://github.com/NLDCSC/nldcsc",
"Homepage": "https://github.com/NLDCSC/nldcsc"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f835e9a2885ad98d4083ba9eb730382ae227c00c818516ee2a4a868b45a6795b",
"md5": "b0db8b171eaca0b0b8c8a9de5f21685a",
"sha256": "78741400337ae861f09bf9590d8972380bd4cf0a788e54147682cbf869aa9ae8"
},
"downloads": -1,
"filename": "nldcsc-0.3.12-py3-none-any.whl",
"has_sig": false,
"md5_digest": "b0db8b171eaca0b0b8c8a9de5f21685a",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.10",
"size": 105267,
"upload_time": "2024-12-21T12:11:38",
"upload_time_iso_8601": "2024-12-21T12:11:38.592499Z",
"url": "https://files.pythonhosted.org/packages/f8/35/e9a2885ad98d4083ba9eb730382ae227c00c818516ee2a4a868b45a6795b/nldcsc-0.3.12-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "8e3d34b1e8d4570951ba60cc3e736d8b0228c12033c00e52ee94efb435092202",
"md5": "e55597067e260526128390b9d9cc80c9",
"sha256": "499b6418ed15a2472577bd1662174d80551c5c078ff41043dd3c71ffc47e2c67"
},
"downloads": -1,
"filename": "nldcsc-0.3.12.tar.gz",
"has_sig": false,
"md5_digest": "e55597067e260526128390b9d9cc80c9",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.10",
"size": 87365,
"upload_time": "2024-12-21T12:11:41",
"upload_time_iso_8601": "2024-12-21T12:11:41.857529Z",
"url": "https://files.pythonhosted.org/packages/8e/3d/34b1e8d4570951ba60cc3e736d8b0228c12033c00e52ee94efb435092202/nldcsc-0.3.12.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-21 12:11:41",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "NLDCSC",
"github_project": "nldcsc",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "nldcsc"
}