Python asyncio

asyncio async/await 構文を利用して並行処理を行う シングルスレッドで動作する並行処理のためのライブラリ コルーチン定義関数(Coroutine function definition) 8.9.1. コルーチン関数定義 コルーチン定義関数は コルーチンオブジェクトを返す。 (ジェネレータベースの)コルーチン(yield) 単純な関数呼び出しによるサブルーチンとは異なり、呼び出し元と呼び出し先を行ったり来たりするような関係性のルーチン ジェネレータを利用してコルーチンを実装する(yield) 『コルーチンは処理を中断した後、続きから処理を再開できる』= ジェネレータは処理を中断・再開できるので、コルーチンであると言える send 呼び出しもとからデータ可能 native coroutine(async) async の付いている関数定義は、generator と同じように、呼び出しをしても直ちに実行はされない関数 await で実行終了を待つ 非同期ジェネレータ(AsyncGenerator) async generator 通常のジェネレータと違って非同期ジェネレータはジェネレータ関数自体の戻り値を返すことはできません asend : 非同期ジェネレータでも呼び出し元から、ジェネレータ関数に値を通知することができます 資料 Python で学ぶ、コルーチンと非同期処理 図解「generator・native coroutine・with」 〜 関心やコードを分離する文法と、処理順序・構造

2024年7月31日 · 1 分

Server Sent Events

SSE MDN: サーバー送信イベントの使用 python で SSE (server side events) の例を作ってみて遊んでみた Server-Sent Events と WebSocket の簡単な実装例

2024年7月24日 · 1 分

金融機関

金融機関 自己資本比率 自己資本とは返済する必要のない資金のことです。 自己資本比率とは総資産のうち、万が一の場合に貸倒れの可能性がある資産に対して、資本金など自己資本がどれくらいあるかを示す指標のことです。 記事: 銀行の自己資本比率 BIS 規制 3 段階(バーゼル3): 狭義の中核的自己資本(コア Tier1) (普通株と内部留保のみ) 中核的自己資本(Tier1)(+優先株、優先出資証券) 総資本 バーゼル 1, 2, 3 バーゼル I: (対日本メガバンク) 国際的な銀行システムの健全性の強化と、国際業務に携わる銀行間の競争上の不平等の軽減を目的として策定 銀行の自己資本比率の測定方法や、達成すべき最低水準(8%以上) バーゼル II: (1)最低所要自己資本比率規制(リスク計測の精緻化) (2)銀行自身による経営上必要な自己資本額の検討と当局によるその妥当性の検証 (3)情報開示の充実を通じた市場規律の実効性向 達成すべき最低水準(8%以上)はバーゼル I と変わらない 銀行が抱えるリスク計測(自己資本比率を算出する際の分母)の精緻化 バーゼル III:(リーマンショックと世界金融危機の反省) 世界的な金融危機の再発を防ぎ、国際金融システムのリスク耐性を高めることを目的 銀行が想定外の損失に直面した場合でも経営危機に陥ることのないよう、自己資本比率規制が厳格化 急な資金の引き出しに備えるための流動性規制 過大なリスクテイクを抑制するためのレバレッジ比率規制等が導入 規制を設計する際、金融システム全体の安定性を維持するというマクロ・プルーデンスの観点が重視されている 資料 Tier1(基本的項目) Tier2(補完的項目) (有価証券含み益、一般貸倒引当金、劣後債・劣後ローンなど) 国際決済銀行(BIS) バーゼル合意、バーゼル I、II、III とは何ですか? いわゆる BIS 規制とは何ですか?

2024年7月18日 · 1 分

FastAPI

FastAPI FastAPI入門 FastAPI を用いた API 開発テンプレート 【FastAPI】Uvicorn と Gunicorn、WSGI と ASGI、ワーカープロセスについて実施コマンドと共に解説 Hypercorn+FastAPI のコンテナイメージを作成してみる Hypercorn Django を Hypercorn とともに使う How to deploy any Python Web Application? FastAPI を始める時のメモ(ボツ) How to serve HTTP 1, 2, and 3 in Python 1 poetry add fastapi hypercorn quart filters fastapi-filters: https://pypi.org/project/fastapi-filters/ https://fastapi-filter.netlify.app/ https://github.com/arthurio/fastapi-filter/tree/main その他: https://pypi.org/project/fastapi-query-tools/ モデルマッパー SQLModel(https://sqlmodel.tiangolo.com/) Database Migrations with sqlmodel and alembic FastAPI + SQLModel を使った簡単API開発をやってみた Pythonライブラリ(SQL):SQLModel(応用編-FastAPI) Pythonライブラリ(SQL):SQLModel Alembicでマイグレーション(FastAPI+SQLModel) FastAPI SQLModel 入門 https://github.com/Joichiro433/Blog-fastapi-todo/tree/main

2024年6月24日 · 1 分

pgsql

PostgreSQL Ubunt: 1 sudo apt install -y postgresql-client

2024年6月18日 · 1 分

Flutter

Android インストール % flutter build apk % flutter devices Found 4 connected devices: Pixel 7a (mobile) • 38211JEHN05972 • android-arm64 • Android 14 (API 34) sdk gphone64 arm64 (mobile) • emulator-5554 • android-arm64 • Android 14 (API 34) (emulator) macOS (desktop) • macos • darwin-arm64 • macOS 14.4.1 23E224 darwin-arm64 Chrome (web) • chrome • web-javascript • Google Chrome 124.0.6367.203 Found 1 wirelessly connected device: iPhone13Pro (mobile) • 00008110-000150C21440401E • ios • iOS 17.4.1 21E236 Run "flutter emulators" to list and start any available device emulators. % flutter install -d 38211JEHN05972 Installing app-release.apk to Pixel 7a... Uninstalling old version... Installing build/app/outputs/flutter-apk/app-release.apk... 6.1s ios [Flutter]iOS のビルドで失敗したらまず試すこと 10 選

2024年5月14日 · 1 分

OAuth: PKCE

OAuth PKCE Authorization Code with PKCE on Django using django-oauth-toolkit PKCE_REQUIRED RFC 7636 - Proof Key for Code Exchange by OAuth Public Clients 日本語訳

2024年2月28日 · 1 分

Django: Push Notification

Django: Push Notification https://github.com/jazzband/django-push-notifications https://github.com/xtrinch/fcm-django APNS (Apple) APNs とは?設定と実装方法を解説! Generation of an APNS PEM file Establishing a token-based connection to APNs FCM/GCM(Google) Firebase でローコードなプッシュ通知を実装してみた Web Push https://github.com/safwanrahman/django-webpush https://github.com/web-push-libs/pywebpush https://github.com/jazzband/django-push-notifications https://github.com/elishowk/django-webpush-demo django-push-notifications を使って、Web Push 通知を実装する Web Push でブラウザにプッシュ通知を送ってみる ブラウザでプッシュ通知を実装してみた Web Push のサーバーサイドの処理〜VAPID と Message Encription を中心に〜 iOS16.4 から iOS の Safari でも Web プッシュが受け取れるようになったので AWS の機能でも試してみた! – 前編 (ローカルでの Web プッシュ通知と PWA 化) iOS16.4 から iOS の Safari でも Web プッシュが受け取れるようになったので AWS の機能でも試してみた! – 後編 (リモートでの Web プッシュ通知) Spec: ...

2024年2月27日 · 1 分

django-redis: lock

djanog-redis: cache.lock lock https://github.com/jazzband/django-redis/blob/d94a7f9644b96cc37743914fce899cca942c032a/django_redis/cache.py#L177 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 class RedisCache(BaseCache): ... @omit_exception def lock(self, *args, **kwargs): return self.client.lock(*args, **kwargs) def __init__(self, server: str, params: Dict[str, Any]) -> None: ... self._client_cls = options.get( "CLIENT_CLASS", "django_redis.client.DefaultClient" ) self._client_cls = import_string(self._client_cls) self._client = None ... DefaultClient https://github.com/jazzband/django-redis/blob/d94a7f9644b96cc37743914fce899cca942c032a/django_redis/client/default.py#L29 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 from redis import Redis class DefaultClient: def __init__(self, server, params: Dict[str, Any], backend: BaseCache) -> None: ... self._clients: List[Optional[Redis]] = [None] * len(self._server) ... def lock( self, key: KeyT, version: Optional[int] = None, timeout: Optional[float] = None, sleep: float = 0.1, blocking_timeout: Optional[float] = None, client: Optional[Redis] = None, thread_local: bool = True, ): if client is None: client = self.get_client(write=True) key = self.make_key(key, version=version) return client.lock( key, timeout=timeout, sleep=sleep, blocking_timeout=blocking_timeout, thread_local=thread_local, ) def get_client( self, write: bool = True, tried: Optional[List[int]] = None, ) -> Redis: """ Method used for obtain a raw redis client. This function is used by almost all cache backend operations for obtain a native redis client/connection instance. """ index = self.get_next_client_index(write=write, tried=tried) if self._clients[index] is None: self._clients[index] = self.connect(index) return self._clients[index] # type:ignore Redis https://github.com/redis/redis-py/blob/6d77c6d715430c30f22147f8c572659d77380a9f/redis/client.py#L88 lock: https://github.com/redis/redis-py/blob/6d77c6d715430c30f22147f8c572659d77380a9f/redis/client.py#L439C1-L511C10 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 class Redis(RedisModuleCommands, CoreCommands, SentinelCommands): def lock( self, name: str, timeout: Optional[float] = None, sleep: float = 0.1, blocking: bool = True, blocking_timeout: Optional[float] = None, lock_class: Union[None, Any] = None, thread_local: bool = True, ): """ Return a new Lock object using key ``name`` that mimics the behavior of threading.Lock. If specified, ``timeout`` indicates a maximum life for the lock. By default, it will remain locked until release() is called. ``sleep`` indicates the amount of time to sleep per loop iteration when the lock is in blocking mode and another client is currently holding the lock. ``blocking`` indicates whether calling ``acquire`` should block until the lock has been acquired or to fail immediately, causing ``acquire`` to return False and the lock not being acquired. Defaults to True. Note this value can be overridden by passing a ``blocking`` argument to ``acquire``. ``blocking_timeout`` indicates the maximum amount of time in seconds to spend trying to acquire the lock. A value of ``None`` indicates continue trying forever. ``blocking_timeout`` can be specified as a float or integer, both representing the number of seconds to wait. ``lock_class`` forces the specified lock implementation. Note that as of redis-py 3.0, the only lock class we implement is ``Lock`` (which is a Lua-based lock). So, it's unlikely you'll need this parameter, unless you have created your own custom lock class. ``thread_local`` indicates whether the lock token is placed in thread-local storage. By default, the token is placed in thread local storage so that a thread only sees its token, not a token set by another thread. Consider the following timeline: time: 0, thread-1 acquires `my-lock`, with a timeout of 5 seconds. thread-1 sets the token to "abc" time: 1, thread-2 blocks trying to acquire `my-lock` using the Lock instance. time: 5, thread-1 has not yet completed. redis expires the lock key. time: 5, thread-2 acquired `my-lock` now that it's available. thread-2 sets the token to "xyz" time: 6, thread-1 finishes its work and calls release(). if the token is *not* stored in thread local storage, then thread-1 would see the token value as "xyz" and would be able to successfully release the thread-2's lock. In some use cases it's necessary to disable thread local storage. For example, if you have code where one thread acquires a lock and passes that lock instance to a worker thread to release later. If thread local storage isn't disabled in this case, the worker thread won't see the token set by the thread that acquired the lock. Our assumption is that these cases aren't common and as such default to using thread local storage.""" if lock_class is None: lock_class = Lock return lock_class( self, name, timeout=timeout, sleep=sleep, blocking=blocking, blocking_timeout=blocking_timeout, thread_local=thread_local, )

2024年1月5日 · 4 分

「この接続ではプライバシーが保護されません」

「この接続ではプライバシーが保護されません」 【18 の方法】「この接続ではプライバシーが保護されません」エラーを解決するには SSL TEST https://www.ssllabs.com/ssltest/index.html DNS CAA DNS CAA (Certification Authority Authorization)利用が標準化 Route 53 が CAA レコードに対応しました!

2023年12月13日 · 1 分