Quickstart
alchemical-storage is a library intended to bridge CRUD operations with SQLAlchemy query constructs
Install
pip install alchemical-storage
Basic Usage
alchemical-storage assumes that you have set up a session (or scoped_session) for your database. This is assumed to have been imported as session in the following example. The table for the defined model is also assumed to be in the database.
-
Set up the model.
"""package/models.py""" from sqlalchemy import orm class Model(orm.DeclarativeBase): """Model class""" __tablename__ = 'models' attr: orm.Mapped[int] = orm.mapped_column(primary_key=True) attr2: orm.Mapped[int] attr3: orm.Mapped[str]
-
Set up the storage schema. The Meta class in the schema should set load_instance to
True."""package/schema.py""" from marshmallow_sqlalchemy import SQLAlchemyAutoSchema from package import Model class ModelSchema(SQLAlchemyAutoSchema): """Model storage schema""" class Meta: model = Model load_instance = True
-
Create a DatabaseStorage instance. Set the
primary_keykeyword argument (defaults to 'slug') to the primary key of the model."""___main___.py""" from package import models from package.schema import ModelSchema storage = DatabaseStorage( session, models.Model, ModelSchema, primary_key="attr",)
-
Use the DatabaseStorage instance.
# __main__.py continued... storage.get(1) # Gets a record from the database storage.put(2, {'attr2': 1, 'attr3': 'test'}) # Puts a record to the database storage.patch(1, {'attr2': 42}) # Update a record in the database storage.delete(1) # Delete a record from the database storage.index() # Get an index of records from the database
-
Commit changes to the database.
session.commit()
License
MIT License. See LICENSE file for more details.
Metadata
Release files for alchemical-storage 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| alchemical_storage-1.0.1.tar.gz | 7.8 kB | Without provenance | Details for alchemical_storage-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| alchemical_storage-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for alchemical_storage-1.0.1-py3-none-any.whl |
Total release size: 18.3 kB
Release files / alchemical_storage-1.0.1.tar.gz
| Download URL | alchemical_storage-1.0.1.tar.gz |
|---|---|
| Size | 7.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
54e69ce7bb8a66fc09bae7d794052d6caf89d333b23529f586a3d741de23baba
|
|
BLAKE2b-256 checksum How to use checksums |
b933abebdca5908e75e551b2487ea3122b6ab9997fbf37b9f6bf2fd93afaf626
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.9.19
|
Release files / alchemical_storage-1.0.1-py3-none-any.whl
| Download URL | alchemical_storage-1.0.1-py3-none-any.whl |
|---|---|
| Size | 10.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
83ccaeb29343a7073bfedeb2583fe23dd723db0fccbf523708fa2c38417d223f
|
|
BLAKE2b-256 checksum How to use checksums |
04229b15bc0ab25fcb9785ba5455212e0c1c77b5854e90bc45d9cae07e733da1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.9.19
|
Security for alchemical-storage 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.