Skip to main content

Setech utilities

Project description

Setech Utilities

Python utility library for API clients, logging, and various development tasks.

Installation

Install the package using pip:

pip install setech

Or with virtualenv (recommended):

python -m venv .venv 
source .venv/bin/activate # On Linux/macOS

Extra Dependencies

The following optional dependencies are available:

Extra Description
django Django support (>=5.2, django-crum, django-model-utils)
drf Django REST Framework with full Django stack
dns DNS utilities (dnspython with dnssec, doh, idna support)
dns-redis DNS cache using Redis backend

Install extras:

pip install "setech[django]"      # Django support
pip install "setech[drf]"         # Django REST Framework
pip install "setech[dns]"         # DNS utilities
pip install "setech[dns-redis]"   # DNS cache with Redis

Core Dependencies

The package requires the following core dependencies:

  • httpx2[http2]
  • num2words
  • phonenumberslite
  • pydantic
  • unidecode

Example code

API Clients

# integration/client.py
from setech import SyncClient


class LocalClient(SyncClient):
    name = "local"
    _base_url = "https://obligari.serveo.net/ping/local"

    def __init__(self, nonce=None):
        super().__init__(nonce)
        self._session.headers.update(
            {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; rv:123.0) Gecko/20100101 Firefox/123.0"}
        )

    def send_post_ping(self, var1: str, var2: int) -> bool:
        res = self.post("/some-post", json={"variable_one": var1, "second_variable": var2})
        return res.json().get("status")

    def send_put_ping(self, var1: str, var2: int) -> bool:
        res = self.put("/some-put", data={"variable_one": var1, "second_variable": var2})
        return res.json().get("status")

    def send_get_ping(self, var1: str, var2: int) -> bool:
        res = self.get("/some-get", params={"variable_one": var1, "second_variable": var2})
        return res.json().get("status")

    def send_patch_ping(self, var1: str, var2: int) -> bool:
        res = self.put("/some-patch", data=(("variable_one", var1), ("variable_one", var2)))
        return res.json().get("status")

    def send_trace_ping(self, var1: str, var2: int) -> bool:
        res = self.trace("/some-trace", params=(("variable_one", var1), ("variable_one", var2)))
        return res.json().get("status")
# integration/main.py
from integration.client import LocalClient


client = LocalClient()
client.send_post_ping("asd", 123)
client.send_put_ping("asd", 123)
client.send_get_ping("asd", 123)
client.send_patch_ping("asd", 123)
client.send_trace_ping("asd", 123)

Log output

Simple

[14d709e02c0c] Preparing POST request to "https://obligari.serveo.net/ping/local/some-post"
[14d709e02c0c] Sending request with payload=b'{"variable_one": "asd", "second_variable": 123}'
[14d709e02c0c] Response response.status_code=200 str_repr_content='{"status":true,"request_id":62}'
[14d709e02c0c] Preparing GET request to "https://obligari.serveo.net/ping/local/some-get"
[14d709e02c0c] Sending request with payload=None
[14d709e02c0c] Response response.status_code=200 str_repr_content='{"status":true,"request_id":63}'

Structured

{"app": "dev", "level": "DEBUG", "name": "APIClient", "date_time": "2024-03-09 22:59:24", "location": "api_client/client.py:_request:71", "message": "[cfbdadc56f53] Preparing POST request to \"https://obligari.serveo.net/ping/local/some-post\"", "extra_data": {"hooks": {"response": []}, "method": "POST", "url": "https://obligari.serveo.net/ping/local/some-post", "headers": {}, "files": [], "data": [], "json": {"variable_one": "asd", "second_variable": 123}, "params": {}, "auth": null, "cookies": null}}
{"app": "dev", "level": "INFO", "name": "APIClient", "date_time": "2024-03-09 22:59:24", "location": "api_client/client.py:_request:74", "message": "[cfbdadc56f53] Sending request with payload=b'{\"variable_one\": \"asd\", \"second_variable\": 123}'", "extra_data": {"payload": "{\"variable_one\": \"asd\", \"second_variable\": 123}"}}
{"app": "dev", "level": "INFO", "name": "APIClient", "date_time": "2024-03-09 22:59:25", "location": "api_client/client.py:_request:81", "message": "[cfbdadc56f53] Response response.status_code=200 str_repr_content='{\"status\":true,\"request_id\":72}'", "extra_data": {"status_code": 200, "content": "{\"status\":true,\"request_id\":72}"}}
{"app": "dev", "level": "DEBUG", "name": "APIClient", "date_time": "2024-03-09 22:59:25", "location": "api_client/client.py:_request:71", "message": "[cfbdadc56f53] Preparing GET request to \"https://obligari.serveo.net/ping/local/some-get\"", "extra_data": {"hooks": {"response": []}, "method": "GET", "url": "https://obligari.serveo.net/ping/local/some-get", "headers": {}, "files": [], "data": [], "json": null, "params": {"variable_one": "asd", "second_variable": 123}, "auth": null, "cookies": null}}
{"app": "dev", "level": "INFO", "name": "APIClient", "date_time": "2024-03-09 22:59:25", "location": "api_client/client.py:_request:74", "message": "[cfbdadc56f53] Sending request with payload=None", "extra_data": {"payload": "{}"}}
{"app": "dev", "level": "INFO", "name": "APIClient", "date_time": "2024-03-09 22:59:25", "location": "api_client/client.py:_request:81", "message": "[cfbdadc56f53] Response response.status_code=200 str_repr_content='{\"status\":true,\"request_id\":74}'", "extra_data": {"status_code": 200, "content": "{\"status\":true,\"request_id\":73}"}}

django features

Using the setech.django in a Django project

Models

The library ships two abstract base models that can be inherited to get timestamping, UUID and audit fields.

# myapp/models.py
from django.db import models 
from setech.django.models import TimeStampedUUIDModel, UserTimeStampedUUIDModel

class Article(TimeStampedUUIDModel): 
    title = models.CharField()
    content = models.TextField()

class Comment(UserTimeStampedUUIDModel): 
    article = models.ForeignKey(Article, on_delete=models.CASCADE)
    text = models.TextField()

What each base class provides

Base model Fields added Notes
TimeStampedUUIDModel uid, created_at, updated_at UUID (v4 or v7 if available) and timestamps
UserTimeStampedUUIDModel created_by, modified_by Populated automatically from the current request when using Django‑CRUM

Validators

setech.django.validators contains a handful of reusable validator functions that can be dropped straight into Django model fields or form/serializer validations.
They wrap common checks such as phone numbers, personal IDs and MX‑record validation for e‑mail addresses.

# myapp/models.py
from django.db import models
from setech.django.models import TimeStampedUUIDModel
from setech.django.validators import django_phone_number_validator, django_personal_code_validator, django_validate_email_mx_domain, validate_image_and_svg_file_extension

class UserProfile(TimeStampedUUIDModel):
    # Phone number in international format, e.g. "+44 20 7946 0958" 
    phone = models.CharField(validators=[django_phone_number_validator])
    
    # Personal ID (SSN/NRIC/etc.) – the validator automatically uses your
    # `settings.COUNTRY_CODE` (e.g. "LV" for Latvia)
    personal_id = models.CharField(max_length=20, validators=[django_personal_code_validator])
    
    # Email address – ensures the domain can receive mail
    email = models.EmailField(validators=[django_validate_email_mx_domain])
    
    # Image file – ensures the file is either image or svg
    picture = models.FileField(validators=[validate_image_and_svg_file_extension])

Customizing the country code

The validators rely on settings.COUNTRY_CODE to decide which format to expect.
Add the following to your Django settings:

# settings.py
from setech.django.constants import Country

...
COUNTRY_CODE = Country.LV # Latvia, change to your locale

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

setech-1.8.0rc1.tar.gz (23.0 kB view details)

Uploaded Source

Built Distribution

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

setech-1.8.0rc1-py3-none-any.whl (34.1 kB view details)

Uploaded Python 3

File details

Details for the file setech-1.8.0rc1.tar.gz.

File metadata

  • Download URL: setech-1.8.0rc1.tar.gz
  • Upload date:
  • Size: 23.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.18 {"installer":{"name":"uv","version":"0.11.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for setech-1.8.0rc1.tar.gz
Algorithm Hash digest
SHA256 022e40a52d131bb689f6d7ff8866b7eda6844495889032d2e0c04ef420beb895
MD5 a3f27d8bef801bdcfc543b6fa252a0f6
BLAKE2b-256 60a83a01e80a519d6e9e5ef491e255c65856bb6b83b35ef59ee83397154fb72a

See more details on using hashes here.

File details

Details for the file setech-1.8.0rc1-py3-none-any.whl.

File metadata

  • Download URL: setech-1.8.0rc1-py3-none-any.whl
  • Upload date:
  • Size: 34.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.18 {"installer":{"name":"uv","version":"0.11.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for setech-1.8.0rc1-py3-none-any.whl
Algorithm Hash digest
SHA256 fd4dca2fe138c495ef87c24a38dc487e3d5f9e0d83a2b4f6dfca9c6758f31ffe
MD5 2e85d59ecfb2fbbacd153796f2b1f85b
BLAKE2b-256 bf7684afc87d2aed2a7cab6aa0e89f073b9a326272f67b2a0faf70ce4e812476

See more details on using hashes here.

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