valar for morghulis
Project description
valar for morghulis
1. install
pip install valar
1. settings
from pathlib import Path
""" Compulsory settings """
DEBUG = True
BASE_DIR = Path(__file__).resolve().parent.parent
BASE_APP = str(BASE_DIR.name)
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
SECRET_KEY = 'django-insecure-of@tfouoq^_f$l!yki#m=6j7)@&kjri$1_$!mca-=%7=+@f@5^'
""" Minimized compulsory settings """
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
INSTALLED_APPS = [
'django.contrib.sessions',
"corsheaders",
'channels',
'src.valar.data',
]
MIDDLEWARE = [
'django.contrib.sessions.middleware.SessionMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
]
CHANNEL_LAYERS = {
"default": {
"BACKEND": "channels.layers.InMemoryChannelLayer"
}
}
CORS_ORIGIN_ALLOW_ALL = True
CORS_ALLOW_CREDENTIALS = True
ROOT_URLCONF = "%s.urls" % BASE_APP
ASGI_APPLICATION = "%s.asgi.application" % BASE_APP
MONGO = {
'host': '<IP>',
'port': '<PORT>',
"username": "<USERNAME>",
"password": '<PASSWORD>'
}
MINIO = {
'endpoint': '<IP>:<PORT>',
'access_key': '<USERNAME>',
"secret_key": "<PASSWORD>",
'secure': False
}
""" Optional settings """
# ALLOWED_HOSTS = ['*']
# LANGUAGE_CODE = 'en-us'
# TIME_ZONE = 'Asia/Shanghai'
# USE_I18N = True
# USE_TZ = False
# SESSION_SAVE_EVERY_REQUEST = True
# SESSION_COOKIE_AGE = 60 * 60
# FILE_UPLOAD_MAX_MEMORY_SIZE = 1024 * 1024 * 100
# DATA_UPLOAD_MAX_MEMORY_SIZE = 1024 * 1024 * 100
2. asgi
from django.core.asgi import get_asgi_application
from channels.routing import ProtocolTypeRouter, URLRouter
from django.urls import re_path
from src.valar.channels import ValarConsumer
application = ProtocolTypeRouter({
'http': get_asgi_application(),
'websocket': URLRouter([
re_path(r'(?P<client>\w+)/$', ValarConsumer.as_asgi()),
])
})
3. migrate
python manage.py makemigrations
python manage.py migrate
4. root urls
from django.urls import path, include
urlpatterns = [
path('data/', include('src.valar.data.urls')),
]
channel_mapping = {
# 'test': test_handler
}
5. channel_handler
import time
from src.valar.channels.sender import ValarSocketSender
from src.valar import Counter
def test_handler(sender: ValarSocketSender):
data = sender.data
length = data.get('length', 50)
counter = Counter(length)
for i in range(length):
time.sleep(0.1)
sender.to_clients(counter.tick(), sender.client, wait=True)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
valar-1.1.3.tar.gz
(10.8 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
valar-1.1.3-py3-none-any.whl
(12.6 kB
view details)
File details
Details for the file valar-1.1.3.tar.gz.
File metadata
- Download URL: valar-1.1.3.tar.gz
- Upload date:
- Size: 10.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4c0cc806cf36d7d6b2d535277b35ae36dc611b32b3ec4cd8d87dbd86a4712b87
|
|
| MD5 |
ff2109837fbb6f2d98d2f870c70e7254
|
|
| BLAKE2b-256 |
fb226b6a40b1176d23d07f841667be194dcc1845e311ba9489c0fb956808e20c
|
File details
Details for the file valar-1.1.3-py3-none-any.whl.
File metadata
- Download URL: valar-1.1.3-py3-none-any.whl
- Upload date:
- Size: 12.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
057c194f1074b8af17a62c1eeee7fdca3947babb36a7385959c75663f3d6b030
|
|
| MD5 |
6578af479754a19554f6ddf85737565e
|
|
| BLAKE2b-256 |
770ff8b909749a82fb446793abc4aa6d4e0348380447218e15b70d65f4221d8a
|