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_digital_dta
adapter = syngenta_digital_dta.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.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | a89d11c62de43992f1d219bc09e703f9d85ae639690a87c93716700194aa3b66 |
|
MD5 | b3ab17581c7fb739982875a02400b788 |
|
BLAKE2b-256 | 11ebf8849f2fc8acf72563952c9918a77a86aafc2da7d9a119e57c45bcb507bd |
Close
Hashes for syngenta_digital_dta-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5aab8bb1194c81829ead2d7eb54c860ecfb9d521e331e79213b913e95880093c |
|
MD5 | fb3f756bec8f30cb6adceebfff7f3e25 |
|
BLAKE2b-256 | 0cc179ef1e86bc58cd4f2342059c238da77c74d876c0186bbcdfe91ccf86e476 |