Giter Club home page Giter Club logo

aws-timestream-module's Introduction

Amazon Timestream Module

Install this package

pip install git+https://[email protected]/VoltaApp/aws-timestream-module.git@<branch_name>

Example usages

Write

from datetime import datetime
from aws_timestream_module.services.write import WriteService

write_service = WriteService(
    # Change the default config here
    # write_client=boto3.Session().client(
    #     "timestream-write",
    #     region_name="ap-southeast-2",
    #     config=Config(
    #         read_timeout=20,
    #         max_pool_connections=5000,
    #         retries={"max_attempts": 10}
    #     )
    # )
)

# Init timestream items from dict items
timestream_items = write_service.get_records_with_multi_type(
    measure_name="example",
    time_field="time_field",
    dimension_fields=["example_field_1"],
    measure_value_fields=["example_field_2"],
    items=[
        {
            "example_field_1": "example_value",
            "time_field": datetime.utcnow(),
            "example_field_2": "example_value"
        }
    ]
)
# output:
# [{'MeasureName': 'example', 'Dimensions': [{'Name': 'example_field_1', 'Value': 'example_value'}], 'MeasureValueType': 'MULTI', 'Time': '1683237700176', 'MeasureValues': [{'Name': 'example_field_2', 'Value': 'example_value', 'Type': 'VARCHAR'}]}]

โ€‹# Ingest timestream items
write_service.write_records(
    database_name="your_database_name",
    table_name="your_table_name",
    records=timestream_items,
    batch_size=100
)

Query

from aws_timestream_module.services.query import QueryService

query_service = QueryService(
    # Change the default config here
    # query_client=boto3.Session().client(
    #     'timestream-query',
    #     region_name="ap-southeast-2",
    # )
)

# Query items using SQL
sql = """
select * from example_table
"""
result = query_service.run_query(query_string=sql)
# output:
# [{'example_field_1': 'example_value', ...}]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.