2026-08-27 16:58
Status:
Tags: Python Frameworks Back End Full Stack Web Development Flask AI IBM IBM Full Stack Software Developer Professional Certificate IBM - Developing AI Applications with Python & Flask
DAAPF - Module 1 - Python Coding Practices and Packaging Concepts
==Application Development and Packaging using Python
-
Reading: Python with Flash for Large-Scale Projects:
- Python with Flask is a lightweight and flexible web application framework. It’s known for its simplicity, minimalism, and ease of use. It is designed as a micro-framework providing a lightweight structure which facilitates developers in building a web application quickly and easily but not compromising on the efficiency and ability to scale up from small-scale projects to larger, more complex applications.
- KEY FLASK CAPABILITIES
- Extensibility and integration: Flask is extensible and developers can add or remove features enabling customization. Flask seamlessly integrates with other Python libraries and frameworks, enabling developers to combine its functionalities with other tools and technologies, thus enhancing its capabilities.
- Transparent documentation: Flask’s documentation is published, allowing developers to use its internal APIs and utilities and find hook points, overrides and signals as per requirement.
- Custom implementation: Out of the box customization and custom classes can be used for things like the request and response objects. The Flask class has many methods designed for sub classing. You can quickly add or customize behavior by sub-classing Flask and using that subclass wherever you instantiate an application class.
- Scaling considerations: You can use scaling in such a way that if you double the number of servers you get about twice the performance. There is only one limiting factor regarding scaling in Flask which is the use of context local proxies. They depend on context which in Flask is defined as being either a thread, process or greenlet. If your server uses some kind of concurrency that is not based on threads or greenlets, Flask will no longer be able to support these global proxies.
- Modular development: Look for ways in which your project can be refactored into a collection of utilities and Flask extensions. Explore the many extensions in the community and look for patterns to build your own extensions if you do not find the tools you need. The best way to improve the tools for larger applications is getting feedback from users.
-
Application Development Lifecycle:
- Application Development Lifecycle- this seems pretty similar to the ISE - Module 1 - The Software Development Lifecycle and what not for reference
- Every single application that gets developed would need to go through certain industrial phases to allow them to actual come into production and creation
- Application Development Lifecycle Phases:
- Requirement Gathering
- Analysis
- Design
- Code and test
- User and System Testing
- Maintenance
- Requirement Gathering this one is the phase where you capture the actual features that someone would want from the application, it’s basically the planning phase if you really think about it
- Like what does your users or your business need it to do, and then also what are the possible technical requirements for the application as well
- Basically the features, pricing, and it needs to run on all browsers or some shit, also identifying the constraints you might have
- Analysis & Design Phase- you have to basically set up how the real bones of this entire application are going to end up working here, so you look at each of the requirements, analysis it and what it might take to get it then
- And then whenever you understand your issue, you design a solution, verify that it works, and if it does, then great, if not, try again
- Throughout this whole process you need to document the design process and structure so you know what it is that you genuinely wanna get done
- Code & Test Phase- basically as it sounds, you use the design documents that you had made, and you actually implement them into software
- You check out whatever stack you need to use, set it all up so it actually works and then test and revise to make sure there are no bugs or anything of the sort. Until you eventually have a well tested and generally good working program
- This testing is purely for making sure you have all features though, it is not always user in-depth
- Types of Testing this is where you have things like unit testing, or even black box testing where you make sure that all parts of the application actual interact with each other how they are supposed to, and that all of the user’s that you might have get the experience out of this that they wanted
- Those two things are called user testing & system testing
- You may need to do things like integration tests which verify that all of the modules of the application work well together and might even work in conjunction with a larger framework
- Production Phase- this is the actual deployment portion of the application where you move all of your final tested programs into the production repository and ship it out for users so they can well, you know, use it
- You should generally do things like not change this repo much, unless you need to give patches or updates to your application
- Maintenance is exactly that, it is mainting maintenaning application and making sure that it continues to work with whatever newer versions of software it might need to work with. It can be things like fixing bugs found by the users, or patching new security vulnerabilities found by exploiters and what not
-
Introduction to Web Applications and APIs:
- Web App is a program that is stored on a remote server and is delivered to someone over the internet
- The user is then able to interact with the application over the browser, and send over data and get data from said remote server using the browser too
- There are generally THREE components of a web server web server, app server, and database
- The web server is the thing that holds things like the HTML document and what not, it’s basically the front end, and is used to communicate with different parts of the back-end, it is the part that the user interacts with
- The app server is actually the part of the web app that is interactive generally and actually lets users do things. This would be things like basically acting sort of as a middle man and operator of them interacting with the database
- The database is then the part of the web app that stores all of the given information on a website, this can be things like secure user information, or even just things like the given information for the produce on the website
- Common Programming Languages-
- Front-End: `JavaScript, HTML, CSS
- Back-End:
Python, Java, Ruby, JavaScript - Web applications are pretty cool because it makes it very simple for someone to access the application as long as they have some form of access to the internet
- It also makes it easy to maintain things like version updates across users, and makes it harder for someone to by pass paid feature for your application
- It also does not make users actually install the given application on their local system
- API (Application Programming Interface) is a way that enables to apps to communicate with one another, inside of a given local environment this is done different than through a REST API that might exist for web development
- For web development, an API would generally pass object information over from one app to another using something like JSON
- See APIs tag for more information on things with APIs and how they generally work
-
Python Style Guide and Coding Practices:
- Python Conventions basically, python is super sensitive to white space and so trying to edit it to look somewhat readable can really really suck
- Therefore, there are common conventions recommended by python (see the link in the references portion of this document) that can help make it more readable
- Using spaces for indentation- basically, they want you to use spaces in order to make things more readable, which I think is somewhat interesting?
- This is because different IDEs consider the number of spaces in a tab differently and therefore if you have multiple different people working on the same project, it might get confusing
- This can actually lead to physical compiling errors inside of python, and so they generally say to use four spaces as your indentation
- They also recommend using black lines as a means to separate different classes and functions, so basically, don’t have unrelated code touching
- This just makes it a little bit easier on the eyes
- They also say to extend this over for things like operators and commas, so if you have something like
1+1you should instead have it be1 + 1in order to make it more readable, which for lots of nested equations I can sort of agree on - And then obviously inside of an array do
[1, 2, 3]instead of[1,2,3]like a psycho path - Obviously use functions to separate large blocks of code and what not so you can call them and separate them out for things like functionality and re-purposing, this is pretty okay but can also be a bit much if you’re doing it for a single one time use, because then you end up with like 40 functions that you don’t know fuck all what they all do
- THEY TELL YOU TO USE LOWERCASE FUNCTION NAMES WITH UNDERSCORES????
- This is absolutely insane to me, camel case or pascal case for functions, otherwise die.
- No the reason they well you to do this is because they have a fuck ton of different libraries where other people who wrote code might have the exact same function name as you which would mess things up, so they basically tell people to use this as a means of distinguishing their own functions
- They tell you to use
camelCasefor classes too?!?! I really thought that pascal case was the main one for that bro but okay - Static Code Anaylsis is basically a way to make sure that the code you write matches a certain style, allowing someone to see how the code is styled without actually executing it and what not
- Seems like a lot of work for something so minor, but I do get why someone might do it
- A common one for python is called
PyLintand they can actually do a bit more and do things like check for programming errors, undefined values, and syntax violations, I think these might be built into some code editors though
-
Unit Testing:
- Unit Testing is a method to validate a unit of code to see if it is operating as it is designed
- Basically, you write your code right, and you need to make sure that the code accomplishes a bunch of different tasks and what not with random input thrown into it
- So what you do, is you hand pick out a few given tests where you know what the output for the function should be, and then you actually input that value into your function and see if you get the right outcome
- The above hand example looks silly because it is over a fairly simple thing like squaring a number, but unit tests for something large, like a compiler for example, where many things could give false outcomes, is very useful
- This can also be used to handle things like edge cases which are basically tests that are not something that would be the regular input, but are still a possible, odd case, that should behave a certain way if it ever does occur
- Generally, in python this is pretty easy because of things like the above-hand library, but there are other methods for many other programming languages and scenarios, tests exist everywhere
- Unit Test Process you generally would write the piece of software, or the module if you well, and then test it locally on your machine against whatever tests you have needed for it
- Then, you will pass it over to something like a CI/CD Server where in which it will run unit tests inside of a more production like environment to see if it works
- If you ever fail one of these tests, then you will get back the test that it failed on and the response that was gotten back from it
- Then it would be your responsibility as a dev to fix it, and once it fully works and passes all tests, you can merge it to the main codebase
- Building Tests
- You can generally have something like
test_myModule.pyfor the code that would be used to test your own code, and then generally you can import your own code, build the tests given whatever syntax you have for your language, and then run it, and see if you pass or not - The above-hand image is a really good example honestly
-
Packaging:
- Packaging vs Modules vs Libraries in python
-
-
-
-
Packages- These are basically a directory of several different python modules, but they must have a
__init__.pyinside of the directory in order to be considered a package and not just a directory of modules -
These generally would serve a total service that can be used directly in your code, its basically a util you import for functionality of code you did not write
-
Some examples include things like
numpy, pytorch, or pandas -
Modules- These are basically just a single
.pyfile with whatever code or script you have running inside of there. You can import a python module into another python file or juypter notebook or whatever you want to import it into, it is basically the lowest level -
Libraries- these are collections of packages, or even just packages themselves. They are a collection of different code inter-working to create some common goal that is generally very reusable and functional. Allowing for importing to let someone accomplish a task without having to write out a bunch of boiler plate themselves like
numpy, pytorch, or pandas
-
- Packaging vs Modules vs Libraries in python
==Summary
- The application development lifecycle has seven phases, including:
- Requirement Gathering: You collect user, business, and technical requirements for the app
- Analysis: You analyze the requirements
- Design: You design the complete solution
- Code and test: You build and test the different components of the app
- User and system test: Users test the app for usability, and you perform system integration testing and performance testing
- Production: The application is available to all end users
- Maintenance: You upgrade or fix any user or system issues
- All web apps are APIs, but not all APIs are web apps. Both share data between apps, but not all APIs require networks like web apps do.
- The PEP8 guidelines for code readability include the following:
- Four spaces for indentation
- Blank lines to separate functions and classes
- Spaces around operators and after commas
- The PEP8 coding conventions for consistency and manageability include:
- Add larger blocks of code inside functions
- Name functions and files using lowercase with underscores
- Name classes using CamelCase
- Name constants in capital letters with underscores separating words
- To ensure that your code adheres to the predefined style and standard without executing the code, you can use the Static code analysis method.
- Unit testing is a method to validate if code units are operating as designed. You must test every unit before integration with the final codebase.
- To create a package:
- Create a folder with the package name
- Create an empty init.py file
- Create the required modules
- In the init.py file, add code to reference the modules needed in the package
- You can verify the package via the bash terminal in a Python shell.
==Cheat Sheet
| Package/Method | Description | Code Example |
|---|---|---|
| Packaging | To create a package, the folder structure is as follows: 1. Project folder → Package name → init.py, module_1.py, module_2.py, and so on. 3. In the init.py file, add code to reference the modules in the package. | module1.py def function_1(arg): return init.py: from . import function_1 |
| Python Style Guide | - Four spaces for indentation - Use blank lines to separate functions and classes - Use spaces around operators and after commas - Add larger blocks of code inside functions - Name functions and files using lowercase with underscores - Name classes using CamelCase - Name constants in capital letters with underscores separating words | def function_1(a, b): if a > b: c = c + 5 else: c = c - 3 return c … c = function_1(a, b) Constant Definition example MAX_FILE_UPLOAD_SIZE |
| Static Code Analysis | Use Static code analysis method to evaluate your code against a predefined style and standard without executing the code. For example, use Pylint to perform static code analysis. | Shell code: pylint code.py |
| Unit Testing | Unit testing is a method to validate if units of code are operating as designed. During code development, each unit is tested. The unit is tested in a continuous integration/continuous delivery test server environment. You can use different test functions to build unit tests and review the unit test output to determine if the test passed or failed. | import unittest from mypackage.mymodule import my_function class TestMyFunction(unittest.TestCase): def test_my_function(self): result = my_function( self.asserEqual(result, unittest.main() |












