Skip to main content

valar for morghulis

Project description

valar for morghulis

1. install

pip install valar

1. settings

from django.core.management.utils import get_random_secret_key
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 = get_random_secret_key()

"""       Valar Options       """

HANDLER_MAPPING = "%s.urls.channel_mapping" % BASE_APP
MONGO_URI = 'mongodb://root:19870120@121.41.111.175:27017/'
MINIO_URL = "s3://admin:password@120.27.8.186:9000"

"""       Minimized compulsory settings       """

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}
INSTALLED_APPS = [
    'django.contrib.sessions',
    "corsheaders",
    'channels',
    'valar.apps.ValarConfig',
]
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

"""       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

no need, valar will auto migration

4. root urls

no need, valar will auto set urlpatterns

5. how to use valar_channel

5.1 set HANDLER_MAPPING in settings

HANDLER_MAPPING = "%s.urls.channel_mapping" % BASE_APP

5.2 create a handler

from valar.channels.sender import ValarSocketSender


def test_handler(sender: ValarSocketSender):
    data = sender.data
    sender.load(data)

5.3 register handler in channel_mapping

channel_mapping = {
    'test': test_handler,
}

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.2.1.tar.gz (28.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.2.1-py3-none-any.whl (38.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: valar-1.2.1.tar.gz
  • Upload date:
  • Size: 28.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.2.1.tar.gz
Algorithm Hash digest
SHA256 16ab5c711e8f4d7f6c36d6165d3006f472e4787c71a8187e56e416e08ebdd01e
MD5 d2e3112c82eccc2dcebda93acf3f575c
BLAKE2b-256 93c7e0ae282a7bfbfe3ddcbfaa4b52e7808aaea293cb08e46951e36d71c6b4a6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: valar-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 38.1 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.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9123196d4fd5851257a912a4326a626ff4bbb7548ad46394c81c135aa3149a26
MD5 8f7bcc1f48c470bfe777d5adc711c5c0
BLAKE2b-256 8789116f22644ec46e5df4141fae9b0a517006312f8470ed5918c1d1f27cf0ba

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