Skip to main content

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 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 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pbshm_core-1.1.6.tar.gz (67.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pbshm_core-1.1.6-py3-none-any.whl (49.5 kB view details)

Uploaded Python 3

File details

Details for the file pbshm_core-1.1.6.tar.gz.

File metadata

  • Download URL: pbshm_core-1.1.6.tar.gz
  • Upload date:
  • Size: 67.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pbshm_core-1.1.6.tar.gz
Algorithm Hash digest
SHA256 b105a04d1a01ee9ae610c2fcaa8f77378dc311e15fd92f4e4333053ea1f4f3e4
MD5 7a5fe839f6ba706b0a2e49b7c92afe34
BLAKE2b-256 6626ac151491b695727d1a551ae1cd1fbbdc86b8d1ba2671fec6df8d48c7c3af

See more details on using hashes here.

Provenance

The following attestation bundles were made for pbshm_core-1.1.6.tar.gz:

Publisher: pypi-publish.yml on dynamics-research-group/pbshm-flask-core

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pbshm_core-1.1.6-py3-none-any.whl.

File metadata

  • Download URL: pbshm_core-1.1.6-py3-none-any.whl
  • Upload date:
  • Size: 49.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pbshm_core-1.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 dc1a8e1d46053a2dadc9114a39da4a58b1b1a1e08ac4428447ccd485f05a7719
MD5 18e79ce04064aebf0ae7088b45730438
BLAKE2b-256 73a94ee856988e35b744eabd8a24ed662005c4f933941d0fea6aa85f2345d0bd

See more details on using hashes here.

Provenance

The following attestation bundles were made for pbshm_core-1.1.6-py3-none-any.whl:

Publisher: pypi-publish.yml on dynamics-research-group/pbshm-flask-core

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page