Skip to main content

Swifty Utils for Django Application

Project description

Django Swifty

Django Swifty is a powerful Django package that simplifies and enhances your Django development experience. It integrates various functionalities, including database management, caching, authentication, logging, and more, to streamline the development process.

Installing the Package in Another Django Project

To install the Django Swifty package in another Django project, follow these steps:

  1. Install the package:

    pip install django_swifty
    
  2. Add to INSTALLED_APPS: After installation, add "django_swifty" to your INSTALLED_APPS setting in your Django project's settings.py file:

    INSTALLED_APPS = [
        ...
        "swifty",
    ]
    
  3. Run migrations: If the package includes any database models, run the following command to apply migrations:

    python manage.py migrate
    

Features

  • Seamless Django Integration: Works out of the box with your Django projects.
  • Easy Configuration: Minimal setup required.
  • Performance Optimized: Built with performance in mind.
  • Customizable: Flexible settings to match your needs.

Database Management

  • SQLAlchemy Integration:
    • Utilizes SQLAlchemy for ORM (Object-Relational Mapping) with session management and transaction handling.
    • Provides a robust way to interact with SQL databases, allowing for complex queries and data manipulation.
  • MongoDB Connector:
    • A dedicated connector for MongoDB that allows seamless interaction with MongoDB databases.
    • Supports connection management and CRUD operations.

Caching

  • Redis Caching:

    • Implements caching using Redis to improve application performance by storing frequently accessed data in memory.
    • Supports various caching strategies, including method-level caching and memoization.
  • Cache Management:

    • Provides a cache manager for setting, getting, and deleting cache entries, making it easy to manage cached data.

Authentication and Authorization

  • JWT Authentication:
    • Supports JSON Web Tokens (JWT) for secure user authentication, allowing for token-based authentication that is stateless and scalable.
  • Custom Permissions:
    • Implements a permission system that checks user attributes against allowed values, controlling access to resources based on user roles and permissions.

Logging

  • Structured Logging:
    • Uses structlog for structured logging, allowing for better log management and analysis.
    • Integrates logging with various components, providing detailed logs for debugging and monitoring.

Utilities

  • Path Parsing Utilities:

    • Provides utility functions for parsing nested data structures using path expressions, making it easier to access deeply nested data.
  • Custom Decorators:

    • Includes decorators for caching and ensuring methods are only called once per instance, enhancing code efficiency and readability.

ViewSets

  • Django REST Framework Integration:
    • Integrates with Django REST Framework to provide a structured way to create APIs.
    • Includes custom viewsets that handle requests, responses, and error handling, making it easier to build RESTful services.

Requirements

  • Python 3.6+
  • Django 2.2+
  • setuptools
  • wheel

Configuration

Database Configuration

Configure your database settings in the settings.py file:

# Example for SQLAlchemy
DB_URL = 'sqlite:///your_database.db'  # Change to your database URL

For MongoDB, set the connection URL:

MONGO_URL = 'mongodb://localhost:27017/your_database'

Caching Configuration

Configure Redis caching in the settings.py file:

REDIS_CONNECTION_POOL = {
    'pool_1': {
        'host': 'localhost',
        'port': 6379,
        'db': 1,
    }
}

JWT Authentication

Set up JWT authentication settings:

JWT_AUTH = {
    'JWT_SECRET_KEY': 'your_secret_key',
    'JWT_ALGORITHM': 'HS256',
    'JWT_EXPIRATION_DELTA': timedelta(days=1),
}

Logging Configuration

Configure logging settings in the settings.py file:

LOGGING_CONFIG = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'console': {
            'class': 'logging.StreamHandler',
        },
    },
    'loggers': {
        'django': {
            'handlers': ['console'],
            'level': 'INFO',
        },
    },
}

ViewSet, Authentication and Authorization Example

To use JWT authentication and custom permissions from Django Swifty, you can define your permissions and apply them in your viewsets:

from swifty.auth.permissions import SwiftyPermission
from swifty.viewsets.viewsets import SwiftyViewSet
from .models import YourModel
from .serializers import YourModelSerializer


class YourCustomPermission(SwiftyPermission):
    permission_layers = [
        {"path": "role", "allowed": ["admin", "superuser"]},
    ]


class YourModelViewSet(SwiftyViewSet):
    queryset = YourModel.objects.all()
    serializer_class = YourModelSerializer
    permission_classes = [YourCustomPermission]  # Apply custom permission

    def perform_create(self, serializer):
        ...

Documentation

For detailed documentation, please visit our documentation page.

Contributing

We welcome contributions! Here's how you can help:

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Authors

  • Phuc Le - Initial work - Github

Acknowledgments

  • Thanks to the Django community for inspiration
  • All the contributors who have helped with the project
  • Special thanks to [list any special acknowledgments]

Made with ❤️ by the Django Swifty Team

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

django_swifty-0.0.95.tar.gz (29.2 kB view details)

Uploaded Source

Built Distribution

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

django_swifty-0.0.95-py3-none-any.whl (39.2 kB view details)

Uploaded Python 3

File details

Details for the file django_swifty-0.0.95.tar.gz.

File metadata

  • Download URL: django_swifty-0.0.95.tar.gz
  • Upload date:
  • Size: 29.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for django_swifty-0.0.95.tar.gz
Algorithm Hash digest
SHA256 7640dad6da8cef8a55ce90dee3a6d04f1ba7cde00dfa61c5210536c6bc756da4
MD5 70b83bcf0b330e81eed09ad097cd80e1
BLAKE2b-256 ad7c179f38a50bc688ccc137e2fb9d986683cec7340a96bcdb5fbe6f2c943127

See more details on using hashes here.

File details

Details for the file django_swifty-0.0.95-py3-none-any.whl.

File metadata

  • Download URL: django_swifty-0.0.95-py3-none-any.whl
  • Upload date:
  • Size: 39.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for django_swifty-0.0.95-py3-none-any.whl
Algorithm Hash digest
SHA256 d87a6e86b6998cb03c42a1ccd06cb70d653965ecca23705381a6b1204e1beefa
MD5 f0d78f4a1a9c5fd474cc14e86e8ea9d7
BLAKE2b-256 f534bd75fa7efb9de5f36bc5c8b24148b6ca2065f812dd2e5f0ba0ce69bdc935

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