Skip to main content

A template library for Python library projects using Poetry and Semantic Release.

Project description

Augmenting Integrations Library Template Repository

CI Status

PyPI Code style: black pre-commit GitHub Actions Conventional Commits semantic-release License Sponsor


📚 Project Resources

📖 Current Documentation 🧪 Test report for last release

Pre-requisites

Install Poetry, AWS CLI, and SAM CLI

Google it and follow the instructions for your platform.

Secret Management

Install chezmoi and age

winget install twpayne.chezmoi
winget install --id FiloSottile.age

Don't forget to setup chezmoi to use age for encryption and github for remote storage.

Set up your AWS OIDC provider (once per account)

Run this once per AWS account (safe to re-run; will no-op if it exists):

aws iam create-open-id-connect-provider `
  --url https://token.actions.githubusercontent.com `
  --client-id-list sts.amazonaws.com

⚡ Getting Started

Very important: Grab your PyPi and TestPyPi names right away, they may not be available later!


Configure Trusted Publisher on PyPI and TestPyPI


Create a .env file for your repository

Copy the following template to a file named .env in the root of your repository. You will fill this out along the way.

# Needed for augint-github to find the repo
GH_REPO=
GH_ACCOUNT=

# Needed to publish to GitHub pages and to push to GitHub during release
GH_TOKEN=

# Needed for pipeline generate docs stage (module name can't contain dashes)
MODULE_NAME=

# Needed for pipeline the test runner in non-matrix mode
PYTHON_VERSION=

##############################
# AWS Pipeline Resources
##############################
TESTING_REGION=us-east-1
TESTING_PIPELINE_EXECUTION_ROLE=
TESTING_CLOUDFORMATION_EXECUTION_ROLE=
TESTING_ARTIFACTS_BUCKET=

Setup your AWS pipeline resources:

  1. Create pipeline resources for stages DEV and PROD. Consider stage names like DevApiPortal and ProdApiPortal.
sam pipeline bootstrap --stage augint-test-testing

Fix the trust policy on the generated PipelineExecutionRole

SAM CLI generates an invalid trust policy (uses ForAllValues:StringLike which fails). Run this after bootstrap:

# Load environment variables from .env file
get-content .env | foreach {
    $name, $value = $_.split('=')
    if ([string]::IsNullOrWhiteSpace($name) -or $name.Contains('#')) {
        # skip empty or comment line in ENV file
        return
    }
    set-content env:\$name $value
}

# Get AWS account ID
$accountId = (aws sts get-caller-identity --query 'Account' --output text)
# Set your GitHub org/user and repo
$githubUserOrOrg = $env:GH_ACCOUNT  
$githubRepo = $env:GH_REPO
$projectPrefix = ($githubRepo.Substring(0, [Math]::Min(9, $githubRepo.Length)))  # first 9 chars

echo "Project prefix: $projectPrefix"
echo "GitHub User/Org: $githubUserOrOrg"
echo "GitHub Repo: $githubRepo"


# Find the generated pipeline execution role
$roleName = aws iam list-roles `
  --query "Roles[?starts_with(RoleName, 'aws-sam-cli-managed-${projectPrefix}') && contains(RoleName, 'PipelineExecutionRole')].RoleName" `
  --output text

if (-not $roleName) {
    Write-Error "Could not find a PipelineExecutionRole for project prefix $projectPrefix"
    exit 1
}

# Define the trust policy
$trustPolicy = @"
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "Federated": "arn:aws:iam::${accountId}:oidc-provider/token.actions.githubusercontent.com"
      },
      "Action": "sts:AssumeRoleWithWebIdentity",
      "Condition": {
        "StringEquals": {
          "token.actions.githubusercontent.com:aud": "sts.amazonaws.com"
        },
        "StringLike": {
          "token.actions.githubusercontent.com:sub": [
            "repo:${githubUserOrOrg}/${githubRepo}:ref:refs/heads/fix/*",
            "repo:${githubUserOrOrg}/${githubRepo}:ref:refs/heads/feat/*",
            "repo:${githubUserOrOrg}/${githubRepo}:ref:refs/heads/dev",
            "repo:${githubUserOrOrg}/${githubRepo}:ref:refs/heads/main"
          ]
        }
      }
    }
  ]
}

"@

echo "Updating trust policy for role: $roleName"
echo "Trust policy: $trustPolicy"

# Update the role trust policy
aws iam update-assume-role-policy `
  --role-name $roleName `
  --policy-document $trustPolicy

Save your .env file

$githubRepo = $env:GH_REPO
chezmoi add .env
chezmoi git add .
chezmoi git commit -- -am "Add .env file for $githubRepo"

Enable pre-commit hooks

pre-commit install
pre-commit install --install-hooks
pre-commit run --all-files


Change augint-library to your project name:

  • in pyproject.toml also, change the version to 0.0.0
  • in .github/workflows/pipeline.yaml
  • in README.md
  • Rename directory: src/augint_librarysrc/<your_project_name>
  • Clear contents of CHANGELOG.md

Push the .env file vars and secrets to your repository

ai-gh-push

Fix up your poetry lock file:

poetry install
poetry lock

Enable Claude Code with MCP servers:

claude mcp add --transport http context7 https://mcp.context7.com/mcp

Finally, push your repo! Don't for get to set your repository's branch protection rules to require a successful run of the pipeline before merging PRs.


Helpful Commands

# "source" an .env file in PowerShell
get-content .env | foreach {
    $name, $value = $_.split('=')
    if ([string]::IsNullOrWhiteSpace($name) -or $name.Contains('#')) {
        # skip empty or comment line in ENV file
        return
    }
    set-content env:\$name $value
}

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

augint_library-1.6.0.tar.gz (35.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

augint_library-1.6.0-py3-none-any.whl (33.8 kB view details)

Uploaded Python 3

File details

Details for the file augint_library-1.6.0.tar.gz.

File metadata

  • Download URL: augint_library-1.6.0.tar.gz
  • Upload date:
  • Size: 35.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for augint_library-1.6.0.tar.gz
Algorithm Hash digest
SHA256 b011aaf96b35c7faf446728c19c63127211148733133d58bd0c01c9a3b7e49b1
MD5 f394b4a539a8486258a2e871962584fd
BLAKE2b-256 e857e649ead47b3fe19d5654299e5b7805af3830dd358b57e780b78c2f19a09e

See more details on using hashes here.

Provenance

The following attestation bundles were made for augint_library-1.6.0.tar.gz:

Publisher: pipeline.yaml on svange/augint-library

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file augint_library-1.6.0-py3-none-any.whl.

File metadata

  • Download URL: augint_library-1.6.0-py3-none-any.whl
  • Upload date:
  • Size: 33.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for augint_library-1.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6af183f382f08b9934fe213e32bb5280548d186a1fb5860e994a436c6117a9f4
MD5 847f7ed7c4eaef72d0e5042405d39c1e
BLAKE2b-256 3b382208527edb2cc6b9711631f8e5f2346d53a9e83673942480d7056a4c7e2e

See more details on using hashes here.

Provenance

The following attestation bundles were made for augint_library-1.6.0-py3-none-any.whl:

Publisher: pipeline.yaml on svange/augint-library

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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