Skip to main content

seamm_datastore

Project description

seamm_datastore

GitHub Actions Build Status codecov

This repository contains the SQLAlchemy models for the SEAMM datastore as well as some associated utilities such as dumping to JSON and checking permissions. These database models and permissions system were developed to be used inside a flask application context in the SEAMM Dashboard. However, you may use this package as a stand-alone (outside of flask) with limited permissions capabilities.

Quickstart

This package contains SQLAlchemy models for the SEAMM datastore. The following gives an example of how to connect to a database in memory. You can switch the database by providing a different database URI.

import seamm_datastore

# Create a database session
connection = seamm_datastore.connect("sqlite:///:memory:")

This will create a sqlite database stored in memory. Using initialize=True will result in a new database being created. You may substitute a different database URI in place of sqlite:///memory. When connecting to a database on disk, you will need to specify an additional argument, initialize=True, if creating a new database.

To login, use the login method. Your username is determined automatically by your username when running connect if initialize is True. An admin user is also create which you can use to login (username=admin, password=admin).

connection.login(username="YOUR_USERNAME", password="default")

To import a datastore at a particular location, do:

connection.import_datastore(FILEPATH)

To use the sample data in this repository,

jobs, projects = connection.import_datastore("seamm_datastore/data/Projects")

JSON data of the added jobs and projects will be returned.

The SEAMMDatastore class has bound database models and a SQLAlchemy session factory which you can work with. These can be interacted with the same as other sqlalchemy models. To retrieve jobs for which you have "read" permissions from the database, use the bound SQLAlchemy models:

jobs = connection.Job.permissions_query("read").all()

To dump to json:

from seamm_datastore.database.schema import JobSchema

# Create job schema
jobs_schema = JobSchema(many=True)

# To retrieve all users in db
all_jobs = connection.Job.permissions_query("read").all()

jobs_json = jobs_schema.dump(all_jobs)

Permissions

The SEAMM datastore has a permissions system built in using flask-authorize for authorization. This provides a "permissions" entry on each resource table (Jobs, Flowcharts, and Projects) where permissions for "owner", "group" and "world". The SEAMM datastore also has capabilities to set "special permissions" for users or groups on specific projects.

Permissions are not automatically enforced when working directly with database models. In the SEAMM Dashboard, permissions are enforced with authentication (verifying the user is who they say they are) using [flask-jwt-extended] and authorization using flask-authorize.

To use the permissions checking mechanisms of flask authorize outside of a flask app, use the helper function here seamm_datastore.SEAMMDatastore.

Copyright

Copyright (c) 2021, Jessica A. Nash (The Molecular Sciences Software Institute)

Acknowledgements

Project based on the Computational Molecular Science Python Cookiecutter version 1.5.

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

seamm_datastore-2022.2.24.1.tar.gz (92.4 kB view details)

Uploaded Source

Built Distribution

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

seamm_datastore-2022.2.24.1-py2.py3-none-any.whl (85.5 kB view details)

Uploaded Python 2Python 3

File details

Details for the file seamm_datastore-2022.2.24.1.tar.gz.

File metadata

  • Download URL: seamm_datastore-2022.2.24.1.tar.gz
  • Upload date:
  • Size: 92.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for seamm_datastore-2022.2.24.1.tar.gz
Algorithm Hash digest
SHA256 80bbf24d7c268ec5c7c9f0164d4ffeeb4cc429da05832db9f0634762c3539f64
MD5 3ef8c11441107a1ac622f3f979ac382b
BLAKE2b-256 781469e4b544496e8e923ec7967c4cd01c9c13a0554c452c0a0e3ac7ab33314f

See more details on using hashes here.

File details

Details for the file seamm_datastore-2022.2.24.1-py2.py3-none-any.whl.

File metadata

  • Download URL: seamm_datastore-2022.2.24.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 85.5 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for seamm_datastore-2022.2.24.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 c128c3bbabee8081783176995e3b2e2cc3b720241e61e29d8a92bee288568718
MD5 80d5281e3cacb28aed55df48a5bd783f
BLAKE2b-256 16627e888efe7f07ac8a72ae5e334efdfb8a911237cee106f2ddc97e1d5923d2

See more details on using hashes here.

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