Skip to main content

Falcon OpenApi

Falcon OpenApi is a plugin for the Falcon Web Framework.

Install

pip3 install falcon-openapi

OpenApi Router

Reads an openapi spec and provides automatic routing to Falcon resources. This is achieved by defining either an operationId or x-falcon property on an endpoint. This removes the need to define all endpoints in your main Falcon file. Instead just set the router to OpenApiRouter.

This router inherits from the default Falcon CompiledRouter class, so it supports all methods available to the default router.

Supports json files, yaml files, raw json strings, and raw yaml strings. If no params are specified the plugin will attempt to find openapi-spec.yml or openapi-spec.yaml in the current working directory (see example for structure).

import falcon
import json
import yaml
from falcon_openapi import OpenApiRouter

spec = {
    'paths': {
        '/foo': {
            'get': {
                'operationId': 'controllers.foo.Foo.on_get'
            }
        }
    }
}

# load from file
app = falcon.API(
    router=OpenApiRouter(file_path='openapi-spec.yml')
)

# load from raw json
app = falcon.API(
    router=OpenApiRouter(raw_json=json.dumps(spec))
)

# load from raw yaml
app = falcon.API(
    router=OpenApiRouter(raw_yaml=yaml.dump(spec))
)

operationId

The example below will route all GET /foo requests to controllers.foo.Foo.on_get. Where controllers.foo is the module name, Foo is the class name, and on_get is the method name. Every operationId in your spec should be unique (See openapi operationId). All three parts of the operationId must be specified for the router to work.

openapi: "3.0.0"
info:
  version: 1.0.0
  title: Falcon Openapi Demo
paths:
  /foo:
    get:
      summary: Do foo things
      operationId: controllers.foo.Foo.on_get

I am unsure if operationId will make it into the final version. I may change this to only check for the x-falcon property. I plan on doing more research to determine if this an appropriate way to use the operationId property.

x-falcon

The example below will route all POST /foo requests to the module controllers.foo, the class Foo, and the method on_post. Note: the standard in Falcon is to use the naming scheme on_get, on_post, etc. If no method name is defined in x-falcon, the plugin will attempt to route to the appropriate on_* method.

openapi: "3.0.0"
info:
  version: 1.0.0
  title: Falcon Openapi Demo
paths:
  /foo:
    post:
      summary: Do foo things
      x-falcon:
        module: controllers.foo
        class: Foo
        method: on_post

Release files for falcon-openapi 0.5.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for falcon-openapi 0.5.1
File Interpreter ABI Platform
falcon_openapi-0.5.1-py3-none-any.whl Python 3 none any Details

Release files / falcon_openapi-0.5.1-py3-none-any.whl

Download URL falcon_openapi-0.5.1-py3-none-any.whl
Size 5.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
00f9778660888a5a2b2387c0778b1c1b1c292ea32ad2990ad7a328d2f1d6da61
BLAKE2b-256 checksum
How to use checksums
2ec40fa68bc9db58c2c018b5ca899af795bb6d999722c346dd378b8673e7e7a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/41.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.4

Release history Release notifications | RSS feed

This release

0.5.1 This release

1 release file

0.5.0

1 release file

0.4.0

1 release file

0.3.1

1 release file

0.2.0

1 release file

0.1.9

1 release file

0.1.8

1 release file

0.1.7

1 release file

0.1.6

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page