Python flask_sockets.Sockets() Examples

The following are 3 code examples of flask_sockets.Sockets(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module flask_sockets , or try the search function .
Example #1
Source File: test_subscription_transport.py    From graphql-python-subscriptions with MIT License 6 votes vote down vote up
def create_app(sub_mgr, schema, options):
    app = Flask(__name__)
    sockets = Sockets(app)

    app.app_protocol = lambda environ_path_info: 'graphql-subscriptions'

    app.add_url_rule(
        '/graphql',
        view_func=GraphQLView.as_view('graphql', schema=schema, graphiql=True))

    @app.route('/publish', methods=['POST'])
    def sub_mgr_publish():
        sub_mgr.publish(*request.get_json())
        return jsonify(request.get_json())

    @sockets.route('/socket')
    def socket_channel(websocket):
        subscription_server = SubscriptionServer(sub_mgr, websocket, **options)
        subscription_server.handle()
        return []

    return app 
Example #2
Source File: app.py    From fastlane with MIT License 4 votes vote down vote up
def create_app(self, testing):
        self.app = Flask("fastlane")

        self.testing = testing
        self.app.testing = testing
        self.app.error_handlers = []

        for key in self.config.items.keys():
            self.app.config[key] = self.config[key]

        self.app.config["ENV"] = self.config.ENV
        self.app.config["DEBUG"] = self.config.DEBUG
        self.app.original_config = self.config
        self.app.log_level = self.log_level
        self.configure_logging()
        self.connect_redis()
        self.configure_queue()
        #  self.connect_queue()
        self.config_blacklist_words_fn()

        self.configure_basic_auth()
        self.connect_db()
        self.load_executor()
        self.load_error_handlers()

        enable_cors = self.app.config["ENABLE_CORS"]

        if (
            isinstance(enable_cors, (str, bytes)) and enable_cors.lower() == "true"
        ) or (isinstance(enable_cors, (bool)) and enable_cors):
            origin = self.app.config["CORS_ORIGINS"]
            self.app.logger.info(f"Configured CORS to allow access from '{origin}'.")
            CORS(self.app)

        metrics.init_app(self.app)
        self.app.register_blueprint(metrics.bp)
        self.app.register_blueprint(healthcheck)
        self.app.register_blueprint(enqueue)
        self.app.register_blueprint(task_api)
        self.app.register_blueprint(execution_api)
        self.app.register_blueprint(status)
        self.app.register_blueprint(routes_api)

        self.app.register_blueprint(gzipped.bp)
        gzipped.init_app(self.app)

        sockets = Sockets(self.app)
        sockets.register_blueprint(stream) 
Example #3
Source File: app.py    From dagster with Apache License 2.0 4 votes vote down vote up
def instantiate_app_with_views(context):
    app = Flask(
        'dagster-ui',
        static_url_path='',
        static_folder=os.path.join(os.path.dirname(__file__), './webapp/build'),
    )
    sockets = Sockets(app)
    app.app_protocol = lambda environ_path_info: 'graphql-ws'

    schema = create_schema()
    subscription_server = DagsterSubscriptionServer(schema=schema)

    app.add_url_rule(
        '/graphql',
        'graphql',
        DagsterGraphQLView.as_view(
            'graphql',
            schema=schema,
            graphiql=True,
            # XXX(freiksenet): Pass proper ws url
            graphiql_template=PLAYGROUND_TEMPLATE,
            executor=Executor(),
            context=context,
        ),
    )
    app.add_url_rule('/graphiql', 'graphiql', lambda: redirect('/graphql', 301))
    sockets.add_url_rule(
        '/graphql', 'graphql', dagster_graphql_subscription_view(subscription_server, context)
    )

    app.add_url_rule(
        # should match the `build_local_download_url`
        '/download/<string:run_id>/<string:step_key>/<string:file_type>',
        'download_view',
        download_view(context),
    )

    # these routes are specifically for the Dagit UI and are not part of the graphql
    # API that we want other people to consume, so they're separate for now.
    # Also grabbing the magic global request args dict so that notebook_view is testable
    app.add_url_rule('/dagit/notebook', 'notebook', lambda: notebook_view(request.args))

    app.add_url_rule('/dagit_info', 'sanity_view', info_view)
    app.register_error_handler(404, index_view)
    CORS(app)
    return app