Skip to main content

Weni's common utilities for Python backends

Project description

Weni Commons

A Python library that centralizes common functionality and utilities used across Weni's Django backend applications. This library promotes code reuse, consistency, and maintainability by providing shared components and utilities that can be easily integrated into multiple Django projects.

Installation

Using Poetry (Recommended for Weni projects)

poetry add weni-commons

Using pip

pip install weni-commons

Available Features

Feature Flags

Weni Feature Flags is a Python Library that functions as an abstraction layer between Django projects and GrowthBook.

from weni.feature_flags.services import FeatureFlagsService

# Use the feature flags service
feature_service = FeatureFlagsService()

You can access the complete instructions on how to use its features here.

Session Token Validation

Validate session hashes issued by Connect against centralized Redis. Apply the decorator to any DRF APIView — no per-project validation code required.

Requirements: CACHES must point to the same Redis instance Connect writes to:

CACHES = {
    "default": {
        "BACKEND": "django_redis.cache.RedisCache",
        "LOCATION": env("REDIS_URL"),
        "OPTIONS": {"CLIENT_CLASS": "django_redis.client.DefaultClient"},
    }
}

Usage:

from rest_framework.response import Response
from rest_framework.views import APIView
from weni_commons.auth import require_session_token

@require_session_token
class ContactsView(APIView):
    def get(self, request):
        project = request.weni_session.projeto
        user = request.weni_session.user
        return Response({"project": project, "user": user})

Clients must send the hash via Authorization: Bearer <hash>. Invalid or expired tokens receive 403 Forbidden before the view handler runs.

Optional setting: WENI_SESSION_TOKEN_REDIS_ALIAS (default "default") to select the Redis cache alias.

Requirements

  • Python >= 3.8
  • Django >= 3.2.22
  • Django REST Framework >= 3.12.0
  • Celery >= 5.0.0
  • Redis (via django-redis >= 4.0.0)

Contributing

This library is designed to grow with Weni's needs. If you have common utilities that could benefit multiple Django projects, consider contributing them to this library.

License

This project is licensed under the GNU General Public License v3.0 - see the LICENSE file 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

weni_commons-1.2.0a1.tar.gz (15.7 kB view details)

Uploaded Source

Built Distribution

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

weni_commons-1.2.0a1-py3-none-any.whl (17.1 kB view details)

Uploaded Python 3

File details

Details for the file weni_commons-1.2.0a1.tar.gz.

File metadata

  • Download URL: weni_commons-1.2.0a1.tar.gz
  • Upload date:
  • Size: 15.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.8.18 Linux/6.17.0-1018-azure

File hashes

Hashes for weni_commons-1.2.0a1.tar.gz
Algorithm Hash digest
SHA256 bafbd8b53e29ba202ceea1de0651d3f786c7e3b4dd49361a30e3f7283048badb
MD5 afd50df368370c7391861766765d0d4d
BLAKE2b-256 0fca6334edb76cc5171a9e8b983f1af589e8521cf13289e65c41e20c2f3eb532

See more details on using hashes here.

File details

Details for the file weni_commons-1.2.0a1-py3-none-any.whl.

File metadata

  • Download URL: weni_commons-1.2.0a1-py3-none-any.whl
  • Upload date:
  • Size: 17.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.8.18 Linux/6.17.0-1018-azure

File hashes

Hashes for weni_commons-1.2.0a1-py3-none-any.whl
Algorithm Hash digest
SHA256 4d3b6e5cd01d6e59ff6dc74c46da7d61b69d6504efef15bb2614c59073513712
MD5 886adede43f7f9feafe84b23b63bfb33
BLAKE2b-256 de4da74b5a2633a4788a69482d058f28bb48e576b2bbd9c67a1ad6c8a187ff7f

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