Skip to main content

Retrieves data from aws cost explore as a pandas dataframe.

Project description

cepan

Pypi Version python test lint Code style: black Code style: black License: MIT

Retrieves data from aws cost explore as a pandas dataframe.

Main features

  • Support for input with type hints
  • Retrieving results as pandas.Dataframe

Installation

pip install cepan

Usage

from datetime import datetime

import cepan as ce

df = ce.get_cost_and_usage(
    time_period=ce.TimePeriod(
        start=datetime(2020, 1, 1),
        end=datetime(2020, 1, 2),
    ),
    granularity="DAILY",
    filter=ce.And(
        [
            ce.Dimensions(
                "SERVICE",
                ["Amazon Simple Storage Service", "AmazonCloudWatch"],    
            ),
            ce.Tags("Stack", ["Production"]),
        ]
    ),
    metrics=["BLENDED_COST"],
    group_by=ce.GroupBy(
        dimensions=["SERVICE", "USAGE_TYPE"],
    ),
)
print(df)

All paginated results will be returned as a Dataframe.

          Time                        SERVICE  BlendedCost
0   2020-01-01  Amazon Simple Storage Service   100.000000
1   2020-01-01               AmazonCloudWatch    10.000000

List of currently supported APIs

  • get_dimension_values
  • get_tags
  • get_cost_and_usage

Alias of aws service name

Normally, the Cost Explorer API requires complex and long names to filter by service name. For example, if you only need the value of an EC2 instance, you would need to specify Amazon Elastic Compute Cloud - Compute.

df = ce.get_cost_and_usage(
    time_period=ce.TimePeriod(
        start=datetime(2020, 1, 1),
        end=datetime(2020, 1, 2),
    ),
    granularity="DAILY",
    filter=ce.Dimensions(
        "SERVICE",
        ["Amazon Elastic Compute Cloud - Compute"],    
    ),
    group_by=ce.GroupBy(
        dimensions=["SERVICE", "USAGE_TYPE"],
    ),
)

cepan supports aliases with short service names. If you only need the value of the EC2 instance, you can specify it with EC2.

df = ce.get_cost_and_usage(
    time_period=ce.TimePeriod(
        start=datetime(2020, 1, 1),
        end=datetime(2020, 1, 2),
    ),
    granularity="DAILY",
    filter=ce.Dimensions(
        "SERVICE",
        ["EC2"],    
    ),
    group_by=ce.GroupBy(
        dimensions=["SERVICE", "USAGE_TYPE"],
    ),
)

Correspondence table of aliases is shown in service_alias.tsv. You can also run the show_service_alias method to get the table.

print(ce.show_service_alias())

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cepan-0.2.0.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

cepan-0.2.0-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

Details for the file cepan-0.2.0.tar.gz.

File metadata

  • Download URL: cepan-0.2.0.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.9.1 Darwin/19.6.0

File hashes

Hashes for cepan-0.2.0.tar.gz
Algorithm Hash digest
SHA256 05b5ce2098977811ba2099e7196f47ad704bd20e69239f56de3e48a0cada5940
MD5 b49e61b5ab011e8d84e161891fb54b31
BLAKE2b-256 da9287286a8e322beb18f12e781b086411e552939385ba3d07c207d72d4732cd

See more details on using hashes here.

File details

Details for the file cepan-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: cepan-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 12.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.9.1 Darwin/19.6.0

File hashes

Hashes for cepan-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 707959b6dfb1892a2995f38fb5f81722194ea68f42bc0b67d6b20e75d4c60884
MD5 4368a1c59c4aa82a77237061e3e75437
BLAKE2b-256 87493b44c1b2db6eff36be68f9cd3d471e0327f9f11b6e17ceab569ec9f04837

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page