Skip to content

Commit 2ab27ab

Browse files
committed
First Blood
0 parents  commit 2ab27ab

File tree

10 files changed

+177
-0
lines changed

10 files changed

+177
-0
lines changed

.editorconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
[*]
3+
end_of_line = lf
4+
insert_final_newline = true
5+
charset = utf-8
6+
indent_style = space
7+
indent_size = 4
8+
# Idealy we want to respect the official limit of 100 characters per line
9+
ij_visual_guides=100, 160

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
build
2+
dist
3+
env
4+
ENVIRONMENT
5+
.wercker
6+
.idea

.werckerignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
build
2+
dist
3+
env

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## artifacts-metadata
2+
3+
This library provides a generic and reusable solution to the problem of storing and retrieving complex metadata associated with artifacts, such as those that are the result of machine learning.

artifacts_metadata/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"""
2+
Copyright (c) 2020 AudienceProject ApS (https://audienceproject.com)
3+
"""
4+
from artifacts_metadata.artifacts_metadata_client import ArtifactsMetadataClient
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
"""
2+
Copyright (c) 2020 AudienceProject ApS (https://audienceproject.com)
3+
"""
4+
import time
5+
import uuid
6+
from typing import Dict, Optional
7+
8+
import boto3
9+
10+
11+
class ArtifactsMetadataClient:
12+
"""
13+
Class which provides functionality for:
14+
- logging metadata information about artifacts to DynamoDB
15+
- retrieving metadata information about artifacts from DynamoDB
16+
- searching for artifacts based on various criteria being matched against metadata
17+
"""
18+
19+
def __init__(self, table_name: str = "artifacts_metadata", dynamodb_resource=None):
20+
if dynamodb_resource is None:
21+
session = boto3.session.Session()
22+
dynamodb_resource = session.resource("dynamodb")
23+
self.table = dynamodb_resource.Table(table_name)
24+
25+
def log(self, artifact_type: str, metadata: Optional[Dict[str, object]] = None) -> str:
26+
"""
27+
Stores a dictionary of metadata into DynamoDB. Will always create a record,
28+
it does not update.
29+
If the location key is part of the dictionary, it will look for a {artifact-id}
30+
template variable that will be replaced by the id of the record to be inserted.
31+
32+
@param artifact_type: A string categorization for artifacts.
33+
@param metadata: A dictionary of values. Can be deep, but must conform to the
34+
constraints of a DynamoDB PUT operation.
35+
36+
@return: The id of the artifact.
37+
"""
38+
if metadata is None:
39+
metadata = {}
40+
metadata["id"] = str(uuid.uuid1())
41+
metadata["artifactType"] = artifact_type
42+
metadata["timestamp"] = time.time_ns() // 1000000
43+
if "location" in metadata:
44+
metadata["location"] = metadata["location"].replace("{artifact-id}", metadata["id"])
45+
self.table.put_item(
46+
Item=metadata
47+
)
48+
return metadata["id"]
49+
50+
def get(self, artifact_id: str) -> Dict[str, object]:
51+
"""
52+
Returns the medata associated with a give id.
53+
54+
@param artifact_id: The id of the artifact's metadata as it is stored in DynamoDB
55+
@return: A dictionary of values representing the whole metadata associated with
56+
a particular artifact id.
57+
"""
58+
return self.table.get_item(Key={"id": artifact_id})["Item"]

requirements.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
boto3==1.0.0
2+
3+
# Operational packages
4+
pip==20.0.2 # The ubiquitous dependency manager
5+
pylint==2.4.4 # For detecting Python errors early and keep consistency of the code
6+
pip-tools==4.4.1 # dependency management helper
7+
twine==3.1.1 # For publishing to PyPi

requirements.lock

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#
2+
# This file is autogenerated by pip-compile
3+
# To update, run:
4+
#
5+
# pip-compile --output-file=requirements.lock --pre requirements.in
6+
#
7+
astroid==2.3.3 # via pylint
8+
bleach==3.1.0 # via readme-renderer
9+
boto3==1.0.0
10+
botocore==1.0.0 # via boto3
11+
certifi==2019.11.28 # via requests
12+
chardet==3.0.4 # via requests
13+
click==7.0 # via pip-tools
14+
docutils==0.15.2 # via botocore, readme-renderer
15+
futures==2.2.0 # via boto3
16+
idna==2.8 # via requests
17+
isort==4.3.21 # via pylint
18+
jmespath==0.7.1 # via boto3, botocore
19+
keyring==21.1.0 # via twine
20+
lazy-object-proxy==1.4.3 # via astroid
21+
mccabe==0.6.1 # via pylint
22+
pip-tools==4.4.1
23+
pkginfo==1.5.0.1 # via twine
24+
pygments==2.5.2 # via readme-renderer
25+
pylint==2.4.4
26+
python-dateutil==2.8.1 # via botocore
27+
readme-renderer==24.0 # via twine
28+
requests-toolbelt==0.9.1 # via twine
29+
requests==2.22.0 # via requests-toolbelt, twine
30+
six==1.14.0 # via astroid, bleach, pip-tools, python-dateutil, readme-renderer
31+
tqdm==4.42.1 # via twine
32+
twine==3.1.1
33+
urllib3==1.25.8 # via requests
34+
webencodings==0.5.1 # via bleach
35+
wrapt==1.11.2 # via astroid
36+
37+
# The following packages are considered to be unsafe in a requirements file:
38+
# pip
39+
# setuptools

setup.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import setuptools
2+
3+
setuptools.setup(
4+
name="artifacts-metadata",
5+
version="0.0.1",
6+
author="Cosmin Catalin Sanda",
7+
author_email="[email protected]",
8+
description="A library for managing artifacts metadata in DynamoDB",
9+
long_description="A library that allows generating and storing metadata for artifacts with"
10+
"complex dependencies, parameters and configuration, such as machine learning "
11+
"models.",
12+
url="https://github.com/audienceproject/artifacts-metadata-py",
13+
packages=setuptools.find_packages(),
14+
python_requires=">=3.6",
15+
install_requires=["boto3>=1.0.0"]
16+
)

wercker.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
box:
2+
id: audienceproject/python
3+
username: $DOCKERHUB_ACCOUNT
4+
password: $DOCKERHUB_PASSWORD
5+
tag: 3.6
6+
no-response-timeout: 25
7+
command-timeout: 25
8+
9+
build:
10+
steps:
11+
- script:
12+
name: Setup virtualenv
13+
code: |
14+
virtualenv env --python=python3.6 --clear
15+
env/bin/pip install pylint==2.4.4
16+
- script:
17+
name: PyLint
18+
code: env/bin/pylint artifacts_metadata
19+
20+
deploy:
21+
steps:
22+
- script:
23+
name: Setup virtualenv
24+
code: |
25+
virtualenv env --python=python3.6 --clear
26+
env/bin/pip install twine==3.1.1
27+
- script:
28+
name: Build library
29+
code: env/bin/python setup.py sdist bdist_wheel
30+
- script:
31+
name: Release library
32+
code: env/bin/twine upload --non-interactive dist/*

0 commit comments

Comments
 (0)