A DRY multi-database normalizer.
Project description
Syngenta Digital DTA (Database Adapter)
A DRY multi-database normalizer.
Features
- Use the same package with multiple database engines
- Able to validate your data against predefined schema in code (for no-schems solutions)
- Creates easy pub-sub architecture based on model changes
- Local development support
Philosophy
The dta philosophy is to use one pattern with multiple databases
The dta encourages pub-sub architecture by allowing for the automatic publishing of data over SNS.
Installation
This is a python module available through the pypi registry.
Before installing, download and install python. python 3 or higher is required.
Installation is done using the
pip install
command:
$ pip install syngenta_digital_dta
or
$ pipenv install syngenta_digital_dta
Common Usage: DynamoDB
import os
import syngenta_data_adapter
adapter = syngenta_data_adapter.adapter(
engine='dynamodb',
table=os.getenv('DYNAMODB_TABLE'),
endpoint='http://localhost:4000',
model_schema='v1-table-model',
model_schema_file='application/openapi.yml',
model_identifier='test_id',
model_version_key='modified'
)
Initialize Options
Option Name | Required | Type | Description |
---|---|---|---|
engine |
true | string | name of supported db engine (dynamodb) |
table |
true | string | name of dynamodb table |
endpoint |
false | string | url of the dynamodb table (useful for local development) |
model_schema |
true | string | key of openapi schema this is being set against |
model_schema_file |
true | string | path where your schema file can found (accepts JSON as well) |
model_identifier |
true | string | unique identifier key on the model |
model_version_key |
true | string | key that can be used as a version key (modified timestamps often suffice) |
author_identifier |
false | string | unique identifier of the author who made the change (optional) |
sns_topic_arn |
false | string | sns topic arn you want to broadcast the changes to |
# create
result = adapter.create(
operation='insert', # or overwrite (optional); defaults to insert
data=some_dict_to_insert_into_the_table,
)
# insert
result = adapter.insert(
data=some_dict_to_insert_into_the_table,
)
# get
result = adapter.read(
operation='get', # or query or scan (optional); defaults to get
query={
'Key': {
'example_id': '3'
}
}
)
# get
result = adapter.get(
query={
'Key': {
'example_id': '3'
}
}
)
# update
result = adapter.update(
data=some_dict_to_update_the_model,
operation='get',
query={
'Key': {
'example_id': '3'
}
}
)
# delete
result = adapter.delete(
query={
'Key': {
'example_id': '3'
}
}
)
Contributing
If you would like to contribute please make sure to follow the established patterns and unit test your code:
Unit Testing
To run unit test, enter command:
RUN_MODE=unittest python -m unittest discover
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
Close
Hashes for syngenta_digital_dta-0.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 36d3fb34b0d641e9fda8cbad372889dbd65aa4cff26895260ce5b4309f52e7c7 |
|
MD5 | e1ebd31ee8db4ed6ca033fe1cf4c70e1 |
|
BLAKE2b-256 | 7f50de255ad65a84162948411082b289060c8f9a42ca46f7d0ad50d18274d46a |
Close
Hashes for syngenta_digital_dta-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 30e8ad24b2c3e32654ee3a9e6d49f5c3c28b70e28fd3835f431811ae1f935fad |
|
MD5 | 8885e82fa52440c7a2adc4ec43d60326 |
|
BLAKE2b-256 | 5cbf5a58fdbc957fef9d4264e591b6cb0318cbc466cdb8f02727726d5805dd60 |