Skip to main content

2 posts tagged with "python"

View All Tags

· 2 min read
What is StackQL?
info

stackql is a dev tool that allows you to query and manage cloud and SaaS resources using SQL, which developers and analysts can use for CSPM, assurance, user access management reporting, IaC, XOps and more.

pystackql is now available in PyPI, and documentation for the package is available at Read the Docs. pystackql can be used with pandas, matplotlib, plotly, jupyter and more to run queries and visualize results.

The latest version of stackql for any platform can be installed using:

pip install pystackql

here is a complete example...

pystackql usage

the code used in this example is available here
from pystackql import StackQL
import pandas as pd
provider_auth = {
"aws": {
"credentialsenvvar": "AWS_SECRET_ACCESS_KEY",
"keyIDenvvar": "AWS_ACCESS_KEY_ID",
"type": "aws_signing_v4"
}
}
regions = ["ap-southeast-2", "us-east-1"]
stackql = StackQL(auth=provider_auth)

query = """
SELECT '%s' as region, instanceType, COUNT(*) as num_instances
FROM aws.ec2.instances
WHERE region = '%s'
GROUP BY instanceType
UNION
SELECT '%s' as region, instanceType, COUNT(*) as num_instances
FROM aws.ec2.instances
WHERE region = '%s'
GROUP BY instanceType
""" % (regions[0], regions[0], regions[1], regions[1])

res = stackql.execute(query)
df = pd.read_json(res)
print(df)

which returns a pandas DataFrame like the following:

  instanceType  num_instances          region
0 t2.medium 2 ap-southeast-2
1 t2.micro 7 ap-southeast-2
2 t2.small 4 ap-southeast-2
3 t2.micro 6 us-east-1

Source code for pystackql can be found at stackql/pystackql

Let us know what you think!

· One min read

StackQL is an intelligent API client which uses SQL as a front-end language with support for multi-cloud and SaaS provider environments, you can find more information at github.com/stackql/stackql

StackQL can provide valuable insights into your cloud and SaaS estates, whether for security posture management, cross-cloud entitlements reporting, cost optimization, or asset/inventory management.

As an interactive analysis tool, Jupyter notebooks can leverage StackQL to provide sources for cloud and SaaS provider data.

GCP Nodes

We've recently added magic function support for running StackQL queries in Jupyter notebooks, making the integration between StackQL and Jupyter more seamless. StackQL magic and be used on a line in a cell or the entire cell itself, as shown here:

The stackql-jupyter-demo Docker image is available from Docker Hub. You can find instructions to run using the Docker Hub image and instructions to run using docker-compose at github.com/stackql/stackql-jupyter-demo.

Give us your feedback!