Skip to main content

Shared Python libraries for Penguin Tech applications

Project description

Penguin Tech Python Libraries

Shared Python libraries for Penguin Tech applications.

Installation

pip install penguin-libs

# With all extras
pip install penguin-libs[all]

# With specific extras
pip install penguin-libs[flask]
pip install penguin-libs[grpc]
pip install penguin-libs[http]

Features

Validation

PyDAL-style input validators with Pydantic integration:

from penguin_libs.validation import IsEmail, IsLength, chain
from penguin_libs.pydantic import EmailStr, StrongPassword

# Direct validation
validator = IsEmail()
result = validator("user@example.com")

# Chained validators
validators = chain(IsNotEmpty(), IsLength(3, 255), IsEmail())
result = validators("user@example.com")

# Pydantic models
from pydantic import BaseModel

class User(BaseModel):
    email: EmailStr
    password: StrongPassword

gRPC

Server helpers, client utilities, and security interceptors:

from penguin_libs.grpc import create_server, GrpcClient, AuthInterceptor

# Server
interceptors = [AuthInterceptor(secret_key="your-secret")]
server = create_server(interceptors=interceptors)

# Client
client = GrpcClient('localhost:50051')
with client.channel() as channel:
    stub = MyServiceStub(channel)
    response = client.call_with_retry(stub.MyMethod, request)

HTTP

Resilient HTTP client with retry logic and circuit breaker:

from penguin_libs.http import HTTPClient, HTTPClientConfig, RetryConfig

config = HTTPClientConfig(
    timeout=30.0,
    retry=RetryConfig(max_retries=3, base_delay=1.0)
)
client = HTTPClient(config)
response = client.get("https://api.example.com/users")

Pydantic Integration

Base models and Flask integration:

from penguin_libs.pydantic import (
    RequestModel,
    validated_request,
    model_response,
)

class CreateUserRequest(RequestModel):
    name: str
    email: EmailStr

@app.route('/users', methods=['POST'])
@validated_request(body_model=CreateUserRequest)
def create_user(body: CreateUserRequest):
    return model_response(UserResponse(...))

Modules

  • validation: PyDAL-style validators (string, numeric, network, datetime, password)
  • grpc: gRPC server/client helpers and security interceptors
  • http: HTTP client with retries, circuit breaker, correlation ID
  • pydantic: Base models, Flask integration, custom Annotated types
  • crypto: Cryptographic utilities (placeholder)
  • security: Security utilities (placeholder)

Development

# Install dev dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Format code
black src tests
ruff check src tests

# Type check
mypy src

License

AGPL-3.0 - See LICENSE for details.

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

penguin_libs-0.1.0.tar.gz (42.2 kB view details)

Uploaded Source

Built Distribution

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

penguin_libs-0.1.0-py3-none-any.whl (47.5 kB view details)

Uploaded Python 3

File details

Details for the file penguin_libs-0.1.0.tar.gz.

File metadata

  • Download URL: penguin_libs-0.1.0.tar.gz
  • Upload date:
  • Size: 42.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for penguin_libs-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5b094006e50a468bef926b280f64ff42f3a718972a2d819dc553c368d4c2cefc
MD5 52981a6bea8bd313a5bac8d08a819512
BLAKE2b-256 97ebdf9411ffe97f0bd240ab74fa1ee861cbcc593060efa05b1d71ad1af8c661

See more details on using hashes here.

Provenance

The following attestation bundles were made for penguin_libs-0.1.0.tar.gz:

Publisher: publish.yml on penguintechinc/penguin-libs

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

File details

Details for the file penguin_libs-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: penguin_libs-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 47.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for penguin_libs-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3ebcf4c646cd7fafabe67eef4400d7ff536fd85ecded45bd23756c368e35b366
MD5 30a557be79df0de6877448dc577cd787
BLAKE2b-256 bc0e2deae32c1588c6087ab18704f21c55f09b00d5e4090394743770d2708cbe

See more details on using hashes here.

Provenance

The following attestation bundles were made for penguin_libs-0.1.0-py3-none-any.whl:

Publisher: publish.yml on penguintechinc/penguin-libs

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