# 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**:
```bash
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:
```python
INSTALLED_APPS = [
...
"swifty",
]
```
3. **Run migrations**: If the package includes any database models, run the following command to apply migrations:
```bash
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:
```python
# Example for SQLAlchemy
DB_URL = 'sqlite:///your_database.db' # Change to your database URL
```
For MongoDB, set the connection URL:
```python
MONGO_URL = 'mongodb://localhost:27017/your_database'
```
### Caching Configuration
Configure Redis caching in the `settings.py` file:
```python
REDIS_CONNECTION_POOL = {
'pool_1': {
'host': 'localhost',
'port': 6379,
'db': 1,
}
}
```
### JWT Authentication
Set up JWT authentication settings:
```python
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:
```python
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:
```python
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](https://django-swifty.readthedocs.io/).
## 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](LICENSE) file for details.
## Authors
- **Phuc Le** - _Initial work_ - [Github](https://github.com/hphuc3005)
## 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
Raw data
{
"_id": null,
"home_page": "https://github.com/pypa/sampleproject",
"name": "django-swifty",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": null,
"author": "Fudu",
"author_email": "hphuc3005@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/75/75/229881bf995cd61d3ebc61ce3f9cc0cf267788242399599375f84e29b798/django_swifty-0.0.68.tar.gz",
"platform": null,
"description": "# Django Swifty\n\nDjango 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.\n\n## Installing the Package in Another Django Project\n\nTo install the Django Swifty package in another Django project, follow these steps:\n\n1. **Install the package**:\n\n ```bash\n pip install django_swifty\n ```\n\n2. **Add to INSTALLED_APPS**: After installation, add \"django_swifty\" to your `INSTALLED_APPS` setting in your Django project's `settings.py` file:\n\n ```python\n INSTALLED_APPS = [\n ...\n \"swifty\",\n ]\n ```\n\n3. **Run migrations**: If the package includes any database models, run the following command to apply migrations:\n\n ```bash\n python manage.py migrate\n ```\n\n## Features\n\n- **Seamless Django Integration**: Works out of the box with your Django projects.\n- **Easy Configuration**: Minimal setup required.\n- **Performance Optimized**: Built with performance in mind.\n- **Customizable**: Flexible settings to match your needs.\n\n### Database Management\n\n- **SQLAlchemy Integration**:\n - Utilizes SQLAlchemy for ORM (Object-Relational Mapping) with session management and transaction handling.\n - Provides a robust way to interact with SQL databases, allowing for complex queries and data manipulation.\n- **MongoDB Connector**:\n - A dedicated connector for MongoDB that allows seamless interaction with MongoDB databases.\n - Supports connection management and CRUD operations.\n\n### Caching\n\n- **Redis Caching**:\n\n - Implements caching using Redis to improve application performance by storing frequently accessed data in memory.\n - Supports various caching strategies, including method-level caching and memoization.\n\n- **Cache Management**:\n - Provides a cache manager for setting, getting, and deleting cache entries, making it easy to manage cached data.\n\n### Authentication and Authorization\n\n- **JWT Authentication**:\n - Supports JSON Web Tokens (JWT) for secure user authentication, allowing for token-based authentication that is stateless and scalable.\n- **Custom Permissions**:\n - Implements a permission system that checks user attributes against allowed values, controlling access to resources based on user roles and permissions.\n\n### Logging\n\n- **Structured Logging**:\n - Uses `structlog` for structured logging, allowing for better log management and analysis.\n - Integrates logging with various components, providing detailed logs for debugging and monitoring.\n\n### Utilities\n\n- **Path Parsing Utilities**:\n\n - Provides utility functions for parsing nested data structures using path expressions, making it easier to access deeply nested data.\n\n- **Custom Decorators**:\n - Includes decorators for caching and ensuring methods are only called once per instance, enhancing code efficiency and readability.\n\n### ViewSets\n\n- **Django REST Framework Integration**:\n - Integrates with Django REST Framework to provide a structured way to create APIs.\n - Includes custom viewsets that handle requests, responses, and error handling, making it easier to build RESTful services.\n\n## Requirements\n\n- Python 3.6+\n- Django 2.2+\n- setuptools\n- wheel\n\n## Configuration\n\n### Database Configuration\n\nConfigure your database settings in the `settings.py` file:\n\n```python\n# Example for SQLAlchemy\nDB_URL = 'sqlite:///your_database.db' # Change to your database URL\n```\n\nFor MongoDB, set the connection URL:\n\n```python\nMONGO_URL = 'mongodb://localhost:27017/your_database'\n```\n\n### Caching Configuration\n\nConfigure Redis caching in the `settings.py` file:\n\n```python\nREDIS_CONNECTION_POOL = {\n 'pool_1': {\n 'host': 'localhost',\n 'port': 6379,\n 'db': 1,\n }\n}\n```\n\n### JWT Authentication\n\nSet up JWT authentication settings:\n\n```python\nJWT_AUTH = {\n 'JWT_SECRET_KEY': 'your_secret_key',\n 'JWT_ALGORITHM': 'HS256',\n 'JWT_EXPIRATION_DELTA': timedelta(days=1),\n}\n```\n\n### Logging Configuration\n\nConfigure logging settings in the `settings.py` file:\n\n```python\nLOGGING_CONFIG = {\n 'version': 1,\n 'disable_existing_loggers': False,\n 'handlers': {\n 'console': {\n 'class': 'logging.StreamHandler',\n },\n },\n 'loggers': {\n 'django': {\n 'handlers': ['console'],\n 'level': 'INFO',\n },\n },\n}\n```\n\n### ViewSet, Authentication and Authorization Example\n\nTo use JWT authentication and custom permissions from Django Swifty, you can define your permissions and apply them in your viewsets:\n\n```python\nfrom swifty.auth.permissions import SwiftyPermission\nfrom swifty.viewsets.viewsets import SwiftyViewSet\nfrom .models import YourModel\nfrom .serializers import YourModelSerializer\n\n\nclass YourCustomPermission(SwiftyPermission):\n permission_layers = [\n {\"path\": \"role\", \"allowed\": [\"admin\", \"superuser\"]},\n ]\n\n\nclass YourModelViewSet(SwiftyViewSet):\n queryset = YourModel.objects.all()\n serializer_class = YourModelSerializer\n permission_classes = [YourCustomPermission] # Apply custom permission\n\n def perform_create(self, serializer):\n ...\n```\n\n## Documentation\n\nFor detailed documentation, please visit our [documentation page](https://django-swifty.readthedocs.io/).\n\n## Contributing\n\nWe welcome contributions! Here's how you can help:\n\n1. Fork the repository\n2. Create your feature branch (`git checkout -b feature/AmazingFeature`)\n3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)\n4. Push to the branch (`git push origin feature/AmazingFeature`)\n5. Open a Pull Request\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## Authors\n\n- **Phuc Le** - _Initial work_ - [Github](https://github.com/hphuc3005)\n\n## Acknowledgments\n\n- Thanks to the Django community for inspiration\n- All the contributors who have helped with the project\n- Special thanks to [list any special acknowledgments]\n\n---\n\nMade with \u2764\ufe0f by the Django Swifty Team\n",
"bugtrack_url": null,
"license": null,
"summary": "Swifty Utils for Django Application",
"version": "0.0.68",
"project_urls": {
"Homepage": "https://github.com/pypa/sampleproject"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "2f1cd327a7fff9274d811a85348e6d95679db3faf50a431dbb69c1f06cf8abb8",
"md5": "8cce6a84973444d34ef96b2c43e54f56",
"sha256": "000241ea0203b9e72df4bb70661474dfde0e3502c4bffaa8ebf02edd4c128fcb"
},
"downloads": -1,
"filename": "django_swifty-0.0.68-py3-none-any.whl",
"has_sig": false,
"md5_digest": "8cce6a84973444d34ef96b2c43e54f56",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 38330,
"upload_time": "2024-12-03T03:08:57",
"upload_time_iso_8601": "2024-12-03T03:08:57.450228Z",
"url": "https://files.pythonhosted.org/packages/2f/1c/d327a7fff9274d811a85348e6d95679db3faf50a431dbb69c1f06cf8abb8/django_swifty-0.0.68-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "7575229881bf995cd61d3ebc61ce3f9cc0cf267788242399599375f84e29b798",
"md5": "b4512292b4aad7938d75d3b9793962c7",
"sha256": "ab5223a1fd9b02065fb5366997e7e756fff3f2ea33f358a2de895b420f80ed21"
},
"downloads": -1,
"filename": "django_swifty-0.0.68.tar.gz",
"has_sig": false,
"md5_digest": "b4512292b4aad7938d75d3b9793962c7",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 28390,
"upload_time": "2024-12-03T03:08:58",
"upload_time_iso_8601": "2024-12-03T03:08:58.467384Z",
"url": "https://files.pythonhosted.org/packages/75/75/229881bf995cd61d3ebc61ce3f9cc0cf267788242399599375f84e29b798/django_swifty-0.0.68.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-03 03:08:58",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "pypa",
"github_project": "sampleproject",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "django-swifty"
}