Skip to main content

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',
    '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 valar.channels.consumer 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('valar.data.urls')),
]

channel_mapping = {
    # 'test': test_handler
}

5. channel_handler

import time

from valar.channels.sender import ValarSocketSender
from valar.core.counter 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


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.0.25.tar.gz (22.6 kB view details)

Uploaded Source

Built Distribution

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

valar-1.0.25-py3-none-any.whl (29.8 kB view details)

Uploaded Python 3

File details

Details for the file valar-1.0.25.tar.gz.

File metadata

  • Download URL: valar-1.0.25.tar.gz
  • Upload date:
  • Size: 22.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.6

File hashes

Hashes for valar-1.0.25.tar.gz
Algorithm Hash digest
SHA256 1f6a04128c01afd5764560b69f0896b8086b9a736475725134da4767e8c448f9
MD5 e65d1d2df816536a395a6b64e420db0e
BLAKE2b-256 db5a8636a931f97c3ab8acdc06d83dd5c96989a102194dd149b9d523a9a45195

See more details on using hashes here.

File details

Details for the file valar-1.0.25-py3-none-any.whl.

File metadata

  • Download URL: valar-1.0.25-py3-none-any.whl
  • Upload date:
  • Size: 29.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.6

File hashes

Hashes for valar-1.0.25-py3-none-any.whl
Algorithm Hash digest
SHA256 c42054c084bd2b2200b9abe6dac155b54d50bdbc363bd592f6f7d64e9f1babb6
MD5 74e29e2960b7b8f0d74a4ba013db50f8
BLAKE2b-256 4b6e56e442ea4cac7e4ca21173cb09f8b025303955cb00ffed01547fae48a7e5

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