Skip to content
This repository was archived by the owner on May 14, 2025. It is now read-only.

Files

Latest commit

01ca4a1 · Feb 4, 2022

History

History
This branch is 137 commits behind thomaxxl/safrs:master.

examples

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Sep 23, 2021
Jan 21, 2022
Sep 24, 2020
Sep 23, 2021
Nov 28, 2021
Jul 21, 2020
Sep 23, 2021
Sep 23, 2021
Sep 23, 2021
Nov 28, 2021
Sep 23, 2021
Sep 23, 2021
Sep 23, 2021
Feb 4, 2022
May 6, 2021

Examples

This folder contains some example applications demonstrating different functionality of SAFRS.

Basic Use Case

mini_app.py : a small sample application The example can be started with

PYTHONPATH=. FLASK_APP=mini_app flask run

Relationships

demo_relationship.py : an extension of the mini_app.py to demonstrate relationship functionality. Ex.:

python3 demo_relationship.py 172.16.9.12

Bigger Example

The demo_pythonanywhere_com.py example is deployed here. It demonstrates different functionalities that can be used. Ex.:

python3 demo_pythonanywhere_com.py 172.16.9.12

note, you may have to install the requirements.txt dependencies, or install safrs with pip install safrs[admin]

Example without SQLAlchemy Model

The demo_stateless.py example demonstrates how to create an exposed object that is not based on an SQLAlchemy instance.

GeoAlchemy2 example

demo_geoalchemy.py

Expose Existing Databases:

It is possible to expose existing databases, as an example I implemented the employees and sakila MuySQL test databases with safrs.

For this to work, I used a modified sqlacodegen to generate the sqlalchemy models sakila.py and employees.py .

The Flask webservices are created with expose_sakila.py and expose_employees.py. They can be started as usual:

$ python3 examples/expose_employees.py 172.1.1.2 5000

Exposed sakila database:

Skype Swagger

Unfortunatley, the code generated with sqlacodegen needed some manual changes before it was usable. For example, the declarative column types for INTEGER and SMALLINT didn't work so I had to create small wrappers to fix this:

def SMALLINT(_):
    return db.SMALLINT

def INTEGER(_):
    return db.INTEGER

You may run into similar problems trying to expose other schemas. These problems may be hard to solve if you're unfamiliar with SQLAlchemy. Feel free to open a github issue and I'll try to help you out.