PBSHM Core Library
Project description
PBSHM Core
PBSHM Core is a minimal application built on Flask to enable development of PBSHM modules that consume PBSHM Schema data. It was designed to deal with all the basic requirements of a PBSHM system, allowing developers to focus on implementation of PBSHM modules.
The application includes a initialisation module to configure and set up the system, a authentication module to provide permission-based authorisation of controls, a layout module to provide an app wide layout, a timekeeper module to enable conversion between native python datetime objects and the PBSHM Schema timestamp format, and finally a mechanic module to facilitate easy interaction between available PBSHM Schema versions and your local database. The minimum version of Python required to run the PBSHM Core is version 3.8.10.
For more information on how to create a module for PBSHM Core, please see the module template repository.
Installation
Install the package via pip:
pip install pbshm-core
Setup
Set the Flask application path and environment.
For Linux/Mac:
export FLASK_APP=pbshm
export FLASK_DEBUG=1
For Windows:
set FLASK_APP=pbshm
set FLASK_DEBUG=1
Configure settings and initialise the database with a new root user:
flask init config
flask init db new-root-user
The above steps will prompt you for all the required fields to set up the system.
Running
The application is run via the standard Flask command:
flask run
Accessing data
The PBSHM Core operates under the premise of data silos: where each realm of confidential data has a corresponding silo (a structure collection) where it's data resides. A user will always have access to at least one structure collection (the default collection), but there may be multiple structure collections available to the user.
The code below shows how to access data in the default collection using a MongoDB Aggregation Pipeline on the default_collection:
from pbshm.db import default_collection
populations = {}
for document in default_collection().aggregate([
{"$project":{
"_id":1,
"name":1,
"population":1
}},
{"$group":{
"_id":"$population",
"structures":{"$addToSet":"$name"}
}},
{"$project":{
"_id":0,
"population":"$_id",
"structures":1
}}
]):
populations[document["population"]] = document["structures"]
Tools
The PBSHM Core comes with a few tools which are available via the mechanic and timekeeper modules. The mechanic module enables easy interaction with the PBSHM Schema and your local database. The timekeeper module enables conversions from native python datetime objects into the timestamp format stored within the PBSHM Schema.
To retrieve all versions of the PBSHM Schema available for installation, use the following command:
flask mechanic versions
To create a new collection with the latest version of the PBSHM Schema installed within the collection, use the following command:
flask mechanic new-structure-collection collection-name
To create a new collection with a specific version of the PBSHM Schema installed within the collection, use the following command:
flask mechanic new-structure-collection collection-name --version=v1.0
To convert a python datetime object into UTC nanoseconds since epoch, use the following code:
from datetime import datetime
from pbshm.timekeeper.timekeeper import datetime_to_nanoseconds_since_epoch
now = datetime.now()
nanoseconds = datetime_to_nanoseconds_since_epoch(now)
To convert a UTC nanoseconds since epoch into a native python datetime object, use the following code:
from pbshm.timekeeper.timekeeper import nanoseconds_since_epoch_to_datetime
nanoseconds = 1706884924912888000
date_time = nanoseconds_since_epoch_to_datetime(nanoseconds)
Bug reporting
If you encounter any issues/bugs with the system or the instructions above, please raise an issue through the issues system on GitHub.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pbshm-core-1.1.0.tar.gz.
File metadata
- Download URL: pbshm-core-1.1.0.tar.gz
- Upload date:
- Size: 59.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
608901f762a8be2eed7aa866dc1e0bd192b1254f3a40790918d5b6db2f18e2ed
|
|
| MD5 |
d60a830b8f63feee4b71601af90d5c65
|
|
| BLAKE2b-256 |
7fe980893e8262c79d6bbf40358918adc54b6581d1b8a263f972a15b4c9e8c45
|
File details
Details for the file pbshm_core-1.1.0-py3-none-any.whl.
File metadata
- Download URL: pbshm_core-1.1.0-py3-none-any.whl
- Upload date:
- Size: 48.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
edd055bd66ad0961a8d130e1b50c7945cc6825151bab559abf524642ffe8bfab
|
|
| MD5 |
fd5a9b39ca23b933771932ecdc21171d
|
|
| BLAKE2b-256 |
31bbd57e9d47d0b6d747b9aa58ff904d4805297c4da136620a4b057afb354ba3
|