Skip to main content

SmoothGlue Django Core

Overview

SmoothGlue Django Core provides a robust foundation for creating extendable and secure application features, optimized for highly regulated environments. This project includes reusable Django apps designed to streamline development for applications requiring stringent security and compliance measures.

Key Features

  • Abstract Models: Includes abstract models like AuditModel and TimeAuditModel for audit trail functionality in your models.
  • Reusable Serializers: A set of base serializers for consistent API development.
  • Custom User Model: Extensible user model adaptable to various authentication requirements.
  • Environment-specific Configuration: Designed for easy configuration in different environments (development, staging, production).
  • Authentication Frameworks: Authentication backends for JWT auth, and creating bootstrap superusers.
  • Duplication Utilities: A duplication utility that allows field selection, field mapping and recursive child duplication.
  • Dynamic API Compression: Configurable middleware for compressing API responses with Brotli or Zstandard.

Installation

Prerequisites

  • Python 3.12+
  • Django 5.2+
  • Django REST Framework 3.15.2+

Install SmoothGlue Django Core From PyPI (Official Use)

  1. Use pip and the following command inside the Django project:

    pip install smoothglue_django_core
    
  2. Enable Smoothglue Django Core's apps in your settings.py:

INSTALLED_APPS = [
    # ... other installed apps ...
    'smoothglue.core',
    'smoothglue.authentication',
    'smoothglue.tracker',
    # ... other installed apps ...
]
  1. Database Migrations:

Run the migrations to create the necessary database tables:

python manage.py migrate
  1. Optional: Enable bootstrap user:

Update settings.py to enable the RootAdminBackend, and set the username and password

AUTHENTICATION_BACKENDS = [
    # ...
    "smoothglue.authentication.auth.RootAdminBackend",
    # ...
]
ROOT_ADMIN_USERNAME = "my_admin_user"
ROOT_ADMIN_PASSWORD = "my_admin_password"

You will be able to authenticate with username my_admin_user and password my_admin_password.

  1. Optional: Enable JWT Authentication:

Update settings.py to enable the JWT middleware. This allows users to authenticate with a JWT to all views.

MIDDLEWARE = [
    # ...
    "smoothglue.authentication.auth.platform_authentication_middleware"
    # ...
]
  1. Optional: Enable Dynamic API Compression:

To enable dynamic API compression, complete these steps:

  1. Add the App: Ensure "smoothglue.core" is in your INSTALLED_APPS.

  2. Enable via Settings: Set COMPRESSION_ALGORITHM_ENABLED = True (or a case-insensitive string like "True" or "true") in your settings.py. This ensures no DB hits when disabled. By default, this is set to False.

    COMPRESSION_ALGORITHM_ENABLED = True
    
    MIDDLEWARE = [
        "smoothglue.core.middleware.DynamicCompressionMiddleware",
        # ...
    ]
    
  3. Configure via Admin or Fixtures: Create an ApplicationConfig record in the database where the key is exactly compression_algorithm and the value is your desired algorithm (BR for Brotli, or ZSTD for Zstandard). The default option is NONE (compression disabled). This can be managed via the Django admin or loaded via data fixtures by the consuming application.

  4. Run the development server to confirm the project continues to work.

API Usage

This package exposes several API endpoints to manage users, organizations, and other related data.

Authentication

This package uses JWT-based authentication. The JWT is decoded from the Authorization or Jwt header of the request. In a development environment, ENABLE_SINGLE_USER_MODE can be set to True to bypass JWT authentication and use a default " UnknownUser".

Endpoints

Users

  • GET /users/: Retrieves a list of all users.

  • POST /users/: Creates a new user.

  • GET /users/{id}/: Retrieves a specific user by their ID.

  • PUT /users/{id}/: Updates a specific user.

  • PATCH /users/{id}/: Partially updates a user.

  • DELETE /users/{id}/: Deletes a user.

Organizations

  • GET /organizations/: Retrieves a list of all organizations.

  • POST /organizations/: Creates a new organization.

  • GET /organizations/{id}/: Retrieves a specific organization by its ID.

  • PUT /organizations/{id}/: Updates an organization.

  • PATCH /organizations/{id}/: Partially updates an organization.

  • DELETE /organizations/{id}/: Deletes an organization.

Organization Members

  • GET /org-members/: Retrieves a list of all organization members.

Organization Categories

  • GET /org-categories/: Retrieves a list of all organization categories.

  • POST /org-categories/: Creates a new organization category.

  • GET /org-categories/{id}/: Retrieves a specific organization category by its ID.

  • PUT /org-categories/{id}/: Updates an organization category.

  • PATCH /org-categories/{id}/: Partially updates an organization category.

  • DELETE /org-categories/{id}/: Deletes an organization category.

Active User

  • GET /active_user/: Retrieves the currently authenticated user's information.

Duplication Example

test_item = APIChangeLog.objects.create(
            username="tester1", data={"foo": "bar"}, timestamp=datetime.now()
        )

new_test_item = duplicate_object(
            test_item,
            include_children=False,
            included_fields=["data", "timestamp"],
            field_mapper={"username": "tester45"},
        )

print(len(APIChangeLog.objects.all())) // 2
print(test_item.data == new_test_item.data) // True, since field was included
print(test_item.username == new_test_item.username) // False, since we overrode with mapper

License

This project is licensed under a Proprietary License. See the LICENSE file for more details.

Release files for smoothglue_django_core 1.8.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for smoothglue_django_core 1.8.1
File Size Uploaded
smoothglue_django_core-1.8.1.tar.gz 67.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for smoothglue_django_core 1.8.1
File Interpreter ABI Platform
smoothglue_django_core-1.8.1-py3-none-any.whl Python 3 none any Details

Total release size: 168.4 kB

Release files / smoothglue_django_core-1.8.1.tar.gz

Download URL smoothglue_django_core-1.8.1.tar.gz
Size 67.3 kB
Tags Source
SHA-256 checksum
How to use checksums
7b5aa37835aaf205bf6fddc7cf6f8ebd0d918fe18b1252e1ae312e228fbf8fa2
BLAKE2b-256 checksum
How to use checksums
ad791b624e26cb310ad48718d269d8a202a2134aeb2d576c21a48c578ae3adeb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.4 CPython/3.12.13 Linux/4.18.0-553.115.1.el8_10.x86_64

Release files / smoothglue_django_core-1.8.1-py3-none-any.whl

Download URL smoothglue_django_core-1.8.1-py3-none-any.whl
Size 101.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a64c609e06c773ab33138a5e552b663885b8162f4faac065367d976f322d8231
BLAKE2b-256 checksum
How to use checksums
997793d55f775d49df5d0357b924c14eface9117fe541550bd3fe236d6da1d7d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.4 CPython/3.12.13 Linux/4.18.0-553.115.1.el8_10.x86_64

Release history Release notifications | RSS feed

This release

1.8.1 This release

2 release files

1.8.0

2 release files

1.7.0

2 release files

1.6.2

2 release files

1.6.1

2 release files

1.6.0

2 release files

1.5.8

2 release files

1.5.3

2 release files

1.5.2

2 release files

1.5.1

2 release files

1.4.1

2 release files

1.4.0

2 release files

1.3.4

2 release files

1.3.3

2 release files

1.3.1

2 release files

1.3.0

2 release files

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