Skip to main content

GitHub GitHub Workflow Status (with branch) Coverage PyPI - Downloads PyPI

Introduction

The Formatter helps you to follow the naming patterns of resources defined for your Python application as well as for the IaC (Infrastructure as Code) scripts in Terraform.

Getting started

Following example illustrates how to use the Formatter can help you get names of resources defined with the help of the naming patterns.

# Project configuration
config = {
    "env": "PROD",
    "project": {
        "code": "analytics-datamart",
        "slug": "adm",
        "solution": {
            "code": "exchange-rates",
            "slug": "fx"
        }
    }
}
# Project naming patterns
naming_patterns = {
    "storage": {
        "buckets": {
            "ingress": "${project.slug}--${project.solution.code}--ingress--${lower(env)}",
            "asset": "${project.slug}--${project.solution.code}--assets--${lower(env)}",
        }
    },
    "bigquery": {
        "datasets": {
            "raw": "${project.slug}_${replace(project.solution.code,'-','_')}_raw",
            "reporting": "${project.slug}_${replace(project.solution.code,'-','_')}_reporting",
        }
    }
}

from surquest.utils.config.formatter import Formatter
formatter = Formatter(
    config=config,
    naming_patterns=naming_patterns,
)

# Get the name of the bucket for the ingress data
formatter.get("storage.buckets.ingress") # adm--exchange-rates--ingress--prod
formatter.get("bigquery.datasets.raw") # adm_exchange_rates_raw

Advanced usage

Let's assume we have all the configuration specified in 4 different JSON files as follows:

  • config.cloud.google.env.PROD.json - configuration for the production environment (GCP project details)
  • config.cloud.google.services.json - specification of the GCP services used in the project (e.g. BigQuery, Cloud Storage, Cloud SQL, etc.) - independent on the environment
  • config.solution.json - specification of the solution (e.g. name of the solution, name of the solution owner, etc.) - independent on the environment
  • config.tenants.json - specification of the tenants (e.g. name of the tenant, country of the tenant, etc.) - independent on the environment

If you want to see more details about the configuration files, please check the config directory

from surquest.utils.config.formatter import Formatter

formatter = Formatter(
  config=Formatter.import_config(
    configs={
      "GCP": "path/to/config/config.cloud.google.env.PROD.json",
      "services": "path/to/config/config.cloud.google.services.json",
      "solution": "path/to/config/config.solution.json",
    }
  ),
  naming_patterns=Formatter.load_json(
    path="path/to/config/naming.patterns.json"
  )
)

formatter.get("storage.buckets.ingress") # adm--exchange-rates--ingress--prod

Local development

You are more than welcome to contribute to this project. To make your start easier we have prepared a docker image with all the necessary tools to run it as interpreter for Pycharm or to run tests.

Build docker image

docker build `
--tag python/utils/config/formatter     `
--file package.base.dockerfile `
--target test .

Run tests

docker run --rm -it `
-v "${pwd}:/opt/project" `
-w "/opt/project/test" `
python/utils/config/formatter pytest

Metadata

Release files for surquest-utils-config-formatter 0.0.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 surquest-utils-config-formatter 0.0.2
File Size Uploaded Provenance Actions
surquest_utils_config_formatter-0.0.2.tar.gz 8.5 kB Without provenance Details for surquest_utils_config_formatter-0.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for surquest-utils-config-formatter 0.0.2
File Interpreter ABI Platform Actions
surquest_utils_config_formatter-0.0.2-py2.py3-none-any.whl Python 3, Python 2 none any Details for surquest_utils_config_formatter-0.0.2-py2.py3-none-any.whl

Total release size: 14.4 kB

Release files / surquest_utils_config_formatter-0.0.2.tar.gz

Download URL surquest_utils_config_formatter-0.0.2.tar.gz
Size 8.5 kB
Tags Source
SHA-256 checksum
How to use checksums
7139da58ccf45311d15191e977395d2314f1c483dc628d242c3e2cce75d41bea
BLAKE2b-256 checksum
How to use checksums
422ef0faaae2aa2f771ee8de12eb8d6c6ea0cd9b0b1f6ff464a1e76adf2f4cf4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release files / surquest_utils_config_formatter-0.0.2-py2.py3-none-any.whl

Download URL surquest_utils_config_formatter-0.0.2-py2.py3-none-any.whl
Size 5.9 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
dd70b9b5edaf8ec372b0a41ebb578ecf92e987adc43f7d9c48b9f0242995f4e6
BLAKE2b-256 checksum
How to use checksums
0e88d368a7005175c92e0073088eccbf32b1c80338e4404a4d4db965d520731a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Security for surquest-utils-config-formatter 0.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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