DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
The Latest "Software Integration: The Intersection of APIs, Microservices, and Cloud-Based Systems" Trend Report
Get the report
  1. DZone
  2. Coding
  3. Frameworks
  4. Learn Flask With an App Fiddle

Learn Flask With an App Fiddle

Learn Flask by fiddling with a complete app and database with VSCode in your browser, and discover how to create projects instantly.

Val Huber user avatar by
Val Huber
·
Mar. 02, 23 · Tutorial
Like (3)
Save
Tweet
Share
2.83K Views

Join the DZone community and get the full member experience.

Join For Free

There is a conventional approach to learning a framework such as Flask: learn with a tutorial, then build something small, and gradually increase functionality. There are dozens to hundreds of such tutorials, and they are very helpful.

Here we offer a complementary approach, one that entirely reverses the script.  Build a complete running project you can explore within a minute, then learn how to alter it, debug it - and then how to create it, literally in seconds.

App Fiddle: An In-Action Flask Tutorial

Tools like JSFiddle are extremely useful. Without installation, you can use your browser to explore existing JavaScript/HTML code, alter it, and see the results.

Flask and fiddleHere, we apply this approach to an entire app: an App (Flask) Fiddle (link at the end).

  • Like a JSFiddle, it opens in your browser; no install.
  • But it's a complete Flask app: a running project, with a database, accessed with SQLAlchemy
  • Accessed via VSCode, running in your browser, courtesy of Codespaces
    • Codespaces is a remarkable new product from GitHub. When you click the link at the end, it requisitions a server, installs your project (and all its dependencies, such as Python and Flask), and opens it in VSCode in your browser.
    • You can also use this App Fiddle to explore Codespaces, how to set up a dev container, and use it on your own projects.

The link (at the end) actually opens 3 projects. The first is a minimal Flask/SQLAlchemy app. It has a README: use it to explore the code, run it, alter/debug it, etc. 

Deliver While Learning

But that's not all.

While the firHorse of a different featherst project shows it's pretty simple to create a single endpoint, gather some data, and return it, it's a lot more work to create an entire project (multiple endpoints, an Admin App, etc). That's a horse of an entirely different feather!

So, we've created API Logic Server. It's an open-source Python app, already loaded into our Codespace project.

It creates an entire Flask project with a single command, like this:

ApiLogicServer create --project_name=ApiLogicProject --db_url=nw-


This reads your database schema (here, a version of Northwind) and creates a complete, executable project, instantly:

  • API: An endpoint for each table, with filtering, sorting, pagination, and related data access. Swagger is automatic.

  • Admin UI: Multi-page/Multi-table apps, with page navigations, automatic joins, and declarative hide/show. It executes a YAML file, so basic customizations do not require HTML or JavaScript background.

    • Custom UIs can be built using your tool of choice (React, Angular, etc), using the API.

Fully Customizable: Standard Python, Flask, SQLAlchemy

Creating the executable project requires no background in Flask, SQLAlchemy, or even Python. In fact, you can use the created project to learn these technologies, by "fiddling" with a running system that's already delivering value (e.g, enabling custom UI dev, integration, etc).

That's because the created project is a standard Flask/SQLAlchemy project. Customize and extend it with all the fundamentals you learned in conventional tutorials, and in the App Fiddle, with your favorite IDE.

Unique Spreadsheet-Like Business Rules

As an experienced app developer, I think of projects as about half the back end and half the front end. Your mileage may vary, but the backend is certainly a lot of work.

  • Multi-table derivations and constraints applied on update:
    • E.g., the customer's balance - the sum of the unshipped order amounts - cannot exceed the credit limit
  • Authorization and authentication
    • E.g., users must enter a valid id and password to gain access
    • Their roles determine what database rows they see (e.g., a multi-tenant application).

API Logic Server enables you to declare spreadsheet-like rules to implement these. Rules are a very significant technology, but perhaps the most striking characteristic is that they are 40X more concise than code.  These 5 rules represent the same logic as 200 lines of Python:

Python
 
Rule.constraint(validate=models.Customer,       # logic design translates directly into rules
    as_condition=lambda row: row.Balance <= row.CreditLimit,
    error_msg="balance ({row.Balance}) exceeds credit ({row.CreditLimit})")

Rule.sum(derive=models.Customer.Balance,        # adjust iff AmountTotal or ShippedDate or CustomerID changes
    as_sum_of=models.Order.AmountTotal,
    where=lambda row: row.ShippedDate is None)  # adjusts - *not* a sql select sum...

Rule.sum(derive=models.Order.AmountTotal,       # adjust iff Amount or OrderID changes
    as_sum_of=models.OrderDetail.Amount)

Rule.formula(derive=models.OrderDetail.Amount,  # compute price * qty
    as_expression=lambda row: row.UnitPrice * row.Quantity)

Rule.copy(derive=models.OrderDetail.UnitPrice,  # get Product Price (e,g., on insert, or ProductId change)
    from_parent=models.Product.UnitPrice)


The third project in the fiddle illustrates both the rules and some "standard" Flask/SQLAlchemy customizations. A tutorial is included to help you explore these, run them, see how to debug them, etc.

You can access the app fiddle by following the links at the top of this blog.

API Open source Flask (web framework)

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Orchestration Pattern: Managing Distributed Transactions
  • How Agile Architecture Spikes Are Used in Shift-Left BDD
  • How To Build a Spring Boot GraalVM Image
  • Isolating Noisy Neighbors in Distributed Systems: The Power of Shuffle-Sharding

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: