Skip to main content

Flaskonf

Configuration Driven API

Installation

Under your python environment

pip install flaskonf

Create API with configuration json files

Suppose you have configuration files like following

!ls ../tests/confs/
la.json       shanghai.json
!cat ../tests/confs/*.json
{
    "name":"Los Angeles",
    "country":"United States",
    "sites":["universal studio", "griffith observatory", "union station"]
}
{
    "name":"Shanghai",
    "country":"China",
    "sites":["french concession", "xin tiandi", "disney resort"]
}
from flaskonf.api import FlaskonfAPI
from typing import Dict
app = FlaskonfAPI("AnConfAPI")

Bind the app to the configuration directory

Example directory is for test inputs example, you can just leave it empety for now

app.build_on_config(
    confs_dir="../tests/confs/",
    examples_dir="../tests/examples/" )

Create API blueprint

The syntax looks like creating API, but this is a blueprint based on what we will create an API for each json file

@app.conf_route("/guide/", nobuild=True)
def guide_api(inputs: Dict):
    data = inputs['data']
    conf = data["conf"]
    user = data["user"]
    return {"city_data": conf, "user": user}

app.build_flaskonf()

Notice, the configuration data is accessible in the decorated function

The rest is flask usual you are familiared with, if you run like following, you can visit localhost:6060/guide/la/ or localhost:6060/guide/shanghai/ to test your API

app.run("0.0.0.0", port = 6060)
 * Serving Flask app "AnConfAPI" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off


 * Running on http://0.0.0.0:6060/ (Press CTRL+C to quit)
INFO:werkzeug: * Running on http://0.0.0.0:6060/ (Press CTRL+C to quit)

When loading API components takes effort

eg. when you have to load huge AI model into memory when starting the server

Set nobuild=True

@app.conf_route("/guide2/", nobuild=False)
def build_city_guide(conf_file: str, conf: Dict):
    logging.info(f"{conf}")
    # doing other things for building API here
    # like load huge model into memory with configuration
    def guide_api(inputs: Dict):
        data = inputs['data']
        user = data["user"]
        return {"city_data": conf, "user": user}
    return guide_api

Metadata

Release files for flaskonf 0.0.4

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

Source distribution (sdist)

Source distribution for flaskonf 0.0.4
File Size Uploaded Provenance
flaskonf-0.0.4.tar.gz 121.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for flaskonf 0.0.4
File Interpreter ABI Platform
flaskonf-0.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 243.1 kB

Release files / flaskonf-0.0.4.tar.gz

Download URL flaskonf-0.0.4.tar.gz
Size 121.4 kB
Tags Source
SHA-256 checksum
How to use checksums
3a30fc67d01f8468cf461358738b35faad224f4a9969b46f8498611f7f43f2d1
BLAKE2b-256 checksum
How to use checksums
766795b54a350cce6938523efe144bf94ea5ecdbdeb9d20af0296d7fe7132085
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.4

Release files / flaskonf-0.0.4-py3-none-any.whl

Download URL flaskonf-0.0.4-py3-none-any.whl
Size 121.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
aa6b22b3db0760ebeab4fe2542cb4fbbeb4a2cb34d4734a90594005359676537
BLAKE2b-256 checksum
How to use checksums
7ac8995d7886c5150b85372793679abf3e076e41e88fa740a4112e668385bf03
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.4

Security for flaskonf 0.0.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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