Skip to main content

GCP time series

codecov

Requirements

  • Python 3.10+

Installation

pip install gcpts

Test

poetry run pytest -s -vv

Usage

import gcpts
import pandas as pd
import numpy as np



gcpts_client = gcpts.GCPTS(
    project_id="example_project", 
    dataset_id="example_dataset"
)

# Prepare example data, your data need to have 3 columns named symbol, dt, partition_dt
df = pd.DataFrame(np.random.randn(5000, 4))

df.columns = ['open', 'high', 'low', 'close']

# symbol represent a group of data for given data columns
df['symbol'] = 'BTCUSDT'

# timestamp should be UTC timezone but without tz info
df['dt'] = pd.date_range('2022-01-01', '2022-05-01', freq='15Min')[:5000]

# partition_dt must be date, data will be updated partition by partition with use of this column.
# Every time, you have to upload all the data for a given partition_dt, otherwise older will be gone.
df['partition_dt'] = df['dt'].dt.date.map(lambda x: x.replace(day=1))

gcpts_client.upload(table_name='example_table', df=df)
# Query for raw data.
raw_clsoe = gcpts_client.query(
    table_name='example_table',
    field='close',
    start_dt='2022-02-01 00:00:00', # yyyy-mm-dd HH:MM:SS, inclusive
    end_dt='2022-02-05 23:59:59', # yyyy-mm-dd HH:MM:SS, inclusive
    symbols=['BTCUSDT'],
)

# Query for raw data with resampling
resampeld_daily_close = gcpts_client.resample_query(
    table_name='example_table',
    field='close',
    start_dt='2022-01-01 00:00:00', # yyyy-mm-dd HH:MM:SS, inclusive
    end_dt='2022-01-31 23:59:59', # yyyy-mm-dd HH:MM:SS, inclusive
    symbols=['BTCUSDT'],
    interval='day', # month | week | day | hour | {1,2,3,4,6,8,12}hour | minute | {5,15,30}minute
    op='last', # last | first | min | max | sum
)

Disclaimer

This allows you to have SQL injection. Please use it for your own purpose only and do not allow putting arbitrary requests to this library.

Metadata

Release files for gcpts 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gcpts 0.1.2
File Size Uploaded
gcpts-0.1.2.tar.gz 7.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gcpts 0.1.2
File Interpreter ABI Platform
gcpts-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 14.5 kB

Release files / gcpts-0.1.2.tar.gz

Download URL gcpts-0.1.2.tar.gz
Size 7.0 kB
Tags Source
SHA-256 checksum
How to use checksums
01cc04fad7f3d5184ed7437d20c1b8a3aee34fd7e8a5ad06814f50c0dde97b7a
BLAKE2b-256 checksum
How to use checksums
46199ae78248b339055b6df19eada3da65a471526034e053dcd5873028d45257
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.2.2 CPython/3.10.6 Linux/5.15.0-1034-azure

Release files / gcpts-0.1.2-py3-none-any.whl

Download URL gcpts-0.1.2-py3-none-any.whl
Size 7.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e57eeb7112cd440394896105916580d260a29fcda59d6d49be377f90e192eb3d
BLAKE2b-256 checksum
How to use checksums
f01558da13577fb999dbaf44ae140eb51dbe13cc98076e3ce2a0a68f4b115dc8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.2.2 CPython/3.10.6 Linux/5.15.0-1034-azure

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page