{"id":21017418,"url":"https://github.com/mkader/pyday","last_synced_at":"2025-07-27T18:04:07.486Z","repository":{"id":160677939,"uuid":"635520738","full_name":"mkader/pyday","owner":"mkader","description":null,"archived":false,"fork":false,"pushed_at":"2023-07-01T01:35:05.000Z","size":1219,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-13T17:17:25.151Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mkader.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-02T21:52:05.000Z","updated_at":"2023-05-02T21:53:13.000Z","dependencies_parsed_at":null,"dependency_job_id":"2ead7bd0-8ecd-4a34-9dae-293c4c7980ff","html_url":"https://github.com/mkader/pyday","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mkader/pyday","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkader%2Fpyday","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkader%2Fpyday/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkader%2Fpyday/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkader%2Fpyday/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mkader","download_url":"https://codeload.github.com/mkader/pyday/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkader%2Fpyday/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267399991,"owners_count":24081176,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-27T02:00:11.917Z","response_time":82,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-19T10:19:22.956Z","updated_at":"2025-07-27T18:04:07.432Z","avatar_url":"https://github.com/mkader.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"https://diataxis.fr/ - A systematic framework for technical documentation authoring.\r\n\r\nGitHub Codespaces is a cloud-based development environment that enables developers to write, build, and debug their code directly from their web browser.\r\n\r\nFree APIs to try: Zippopotamus, Sunrise/Sunset, Reddit\r\n\r\npip install urllib3 rich fastapi \"uvicorn[standard]\"\r\n\r\nProcessing APIs in python use urllib, requests or urllib3\r\n\r\n* **PoolManager** is a class in the urllib3 library used to manage connection pools for one or more HTTP connections. \r\n    * It is used to create an instance of an HTTP connection pool with a specified number of connections. \r\n    * You can use this instance to send multiple requests to the same host and reuse the same connection for each request, \r\n    which can result in faster response times and reduced overhead.\r\n\r\n* **Rich** is a Python library for rich text and beautiful formatting in the terminal. \r\n    * It provides various features such as syntax highlighting, progress bars, tables, markdown, and more. \r\n    * It aims to make it easier to create beautiful and informative console output. It supports both Python 3.6+ and PyPy3.\r\n\r\n* **FastAPI** - https://fastapi.tiangolo.com/\r\n    * FastAPI is a web framework for building APIs with Python 3.7+. It is designed to be easy, fast and to provide high performance.\r\n    * It uses the Python type hinting system to validate data types and function parameters, which makes it write and maintain type-safe APIs.\r\n    * FastAPI is a lightweight ASGI (Asynchronous Server Gateway Interface) framework, compatible with a wide range of ASGI servers such as Uvicorn and Hypercorn, which provide high-performance web servers.\r\n    * It contains a built-in OpenAPI and JSON Schema generator, which allows to generate API documentation and client libraries. Additionally, It has built-in support for testing and debugging your API.\r\n\r\n    * **FastAPI is a python framework designed specifically for building HTTP APIs.**\r\n        * Fast to build and fast to execute\r\n        * Relies on python types (via pydnatic)\r\n        * Auto-generated documentation (via Swagger-UI)\r\n        * Based on the OpenAPI specifications.\r\n        * Supports passing parameters in the path, cookies, headers or body.\r\n\r\n    * **Running FastAPI locally**\r\n        * Put code in api/main.py\r\n        * Run the server: uvicorn  api.main:app --reload --port=8000\r\n            * api.main:app specifies the module and the variable name of the application that needs to be run.\r\n            * --reload enables hot-reloading, any code changes, the server will restart automatically.\r\n            * --port=8000, which the server will be listening for incoming requests.\r\n        \r\n        * Try the API and docs : http://127.0.0.1:8000/generate_name, http://127.0.0.1:8000/docs, http://127.0.0.1:8000/redoc, http://127.0.0.1:8000/openapi.json \r\n\r\n* **Testing FastAPI apps**\r\n    * Configuring pytest and coverage\r\n        * Create a requirements-dev.txt file:\r\n            * -r api/requirements.txt\r\n            * fastapi[all]\r\n            * pytest\r\n            * pytest-cov\r\n            * coverage\r\n\r\n            * \"-r api/requirements.txt\" flag,install the required Python packages listed in the api/requirements.txt file.\r\n            * \"fastapi[all]\" package, installs FastAPI with all dependencies (Uvicorn, Pydantic and other libraries)\r\n            * \"pytest\" package is a testing framework that allows you to write and run automated tests for your Python code.\r\n            * \"pytest-cov\" package is a plugin for pytest that provides code coverage reports for your tests.\r\n            * \"coverage\" package is a tool that measures code coverage during Python program execution.\r\n\r\n        * **Configure inside pyproject.toml**\r\n            * [tool.pytest.ini_options]\r\n            * addopts = \"-ra --cov api\"\r\n            * testpaths = [ \"tests\" ]\r\n            * pythonpath = ['.']    \r\n\r\n            * **pyproject.toml is a configuration file** used by modern Python projects that adopt the poetry build tool. It is similar to other configuration files like setup.cfg, setup.py, or requirements.txt, but with additional features and functionalities.\r\n                * \"[tool.pytest.ini_options]\" - contains additional configuration options to pass to pytest, a popular Python testing framework.\r\n                * \"addopts\" - specifies additional command-line options to pass to pytest. \r\n                    * \"-ra\" tells pytest to output all test results\r\n                    * \"--cov api\" enables test coverage reporting for the api module.\r\n                * \"testpaths\" -specifies directories tests (containing all tests).\r\n                * \"pythonpath\" - specifies which directories to include in the Python module search path. In this case, . (the current directory) is included, so that modules in the current directory can be imported and used in the tests.\r\n\r\n    * Create folde and file - \"tests\\test_api.py\"        \r\n    * pip install -r requirements-dev.txt\r\n    * python -m pytest\r\n        Name | Stmts | Miss | Cover\r\n        -|-|-|-\r\n        api/main.py | 19 | 9 |53%\r\n        * not giving missing lines details\r\n    * python -m pytest --cov-report=html\r\n        * it will create folder htmlcov\r\n        * go to the folder, run python3 -m http.server 8000 --bind 127.0.0.1\r\n        * browse to see the coverage report https://127.0.0.1/htmlcov/index.html\r\n\r\n* **Property-based tests with schemathesis**\r\n    * Property-based testing is a type of testing approach that focuses on generating a large number of random inputs to test functions and APIs. Instead of manually creating test, the testing framework generates automatically, based on predefined properties.\r\n\r\n    * Schemathesis is a Python library for property-based testing of APIs. It automatically generates API test cases based on their OpenAPI schema (Swagger). IT generates a large number of random requests to the API and checking that the responses match the expected schema.\r\n\r\n    * Schemathesis also has various features like test coverage analysis, response time tracking, and compatibility with different Python testing frameworks like pytest.\r\n\r\n    * By using schemathesis, developers can perform thorough testing of their APIs with minimal manual effort, which can lead to more reliable and bug-free code. It's useful for ensuring that your API is robust and can handle a variety of inputs and outputs.\r\n\r\n    * Add schemathesis to requirments-dev.txt\r\n        \r\n    * Generaete tests based on the OpenAPI Spec: (\"tests\\property_based.py\")\r\n        ``` mark\r\n            import schemathesis\r\n            from api.main import app\r\n            schema = schemathesis.from_asqi(\"/openapi.json\",app)\r\n            \r\n            #schema.parametrize()\r\n            def test_api():\r\n                response = case.call_asqi()\r\n                case.validate_response(response)\r\n        ```\r\n    pip install -r requirements-dev.txt\r\n\r\n    Run the tests\r\n        pytest -k test_api   \r\n        pytest -v tests/property_based.py \r\n\r\n        Error, when i run pytest -v tests/property_based.py  \r\n\r\n            E       schemathesis.exceptions.CheckFailed: \r\n            E       1. Received a response with a status code, which is not defined in the schema: 404\r\n            E       Declared status codes: 200, 422\r\n            E       Response status: 404\r\n            E       Response payload: `{\"detail\":\"No names available\"}`    \r\n\r\n        To solve the error either add \r\n            (property_based.py)\r\n                if response.status_code == 404:\r\n                    assert response.content == b'{\"detail\":\"No names available\"}'\r\n                else:\r\n                    case.validate_response(response)\r\n            OR main.py\r\n                @app.get(\"/generate_name_qs\", responses={404:{}})\r\n\r\nThrough Visual Code, run unit test\r\n    Configure Python Tests -\u003e Select pytest pytest framework -\u003e select \"tests\" folder -\u003e \"Run Tests\"\r\n\r\nProudctionizing FastAPI apps\r\n    Gunicorn (Green Unicorn), is a Python Web Server Gateway Interface (WSGI) HTTP server.\r\n        It's used in popular Python web frameworks (Flask, Django, Pyramid, and Bottle). It can handle requests from multiple clients simultaneously by pre-forking worker processes to handle each request, resulting in efficient resource utilization.\r\n\r\n        It's easy use and configure (including logging, worker processes, worker class, timeout, and more). It can also be integrated with a wide range of deployment tools, such as Docker, Kubernetes, and Heroku.\r\n\r\n    Gunicorn- won't work windows, it will work on unix\r\n        It's a production-level server that can run multiple worker process\r\n\r\n        Add gunicorn to requirements.txt\r\n            fastapi==0.95.1\r\n            uvicorn[stanadard]==0.22.0\r\n            gunicorn==20.1.0\r\n\r\n        Pip install -r requirements-dev.txt\r\n        Use gunicorn to run FastAPI app using uvicorn worker:\r\n            python -m gunicorn api.main:app --workers 4 --worker-class uvicorn.workers.UvicornWorker --bind 0.0.0.0:8000     \r\n\r\n            This command starts a Gunicorn server to run a Python web application located in api/main.py, using the FastAPI app instance app. The server will run with 4 worker processes to handle incoming requests, using the uvicorn worker class UvicornWorker to support asynchronous handling of requests. The server will listen on all available network interfaces (0.0.0.0) on port 8000.\r\n            \"python -m gunicorn\" invokes the Gunicorn server using the python interpreter.\r\n    \r\n    Configuring gunicorn\r\n        Gunicorn can be configured with a \"gunicorn.conf.py\" file to adjust worker count based on CPU cores\r\n\r\n            # Gunicorn configuration file\r\n            # https://docs.gunicorn.org/en/stable/configure.html#configuration-file\r\n            # https://docs.gunicorn.org/en/stable/settings.html\r\n\r\n            import multiprocessing\r\n\r\n            max_requests = 1000\r\n            max_requests_jitter = 50\r\n            log_file = \"-\"\r\n            bind = \"0.0.0.0:3100\"\r\n            worker_class = \"uvicorn.workers.UvicornWorker\"\r\n            workers = (multiprocessing.cpu_count() * 2) + 1\r\n\r\n        In this particular example, we see the following configurations:\r\n            max_requests: sets the maximum number of requests a worker will process before restarting\r\n            max_requests_jitter: sets the maximum jitter to add to the max_requests value to reduce the likelihood of all workers restarting at the same time\r\n            log_file: sets the location for the Gunicorn server logs, in this case, logs will be sent to standard output (-)\r\n            bind: sets the address and port on which Gunicorn will listen for connections\r\n            worker_class: sets the worker class for handling requests, in this case, it's using UvicornWorker, a worker for the Uvicorn ASGI server\r\n            workers: sets the number of worker processes for handling incoming requests. The number of workers is calculated based on the number of available CPUs, adding 1 and then multiplying by 2.\r\n\r\n        Run command can be simplified to\r\n            cd api\r\n            python -m gunicorn main:app\r\n\r\nHosting an HTTP API on Azure!\r\n    Hosting considerations\r\n        How much traffic do you expect?\r\n        How variable will the traffic be?\r\n        Do you need scale-to-zero?\r\n        What's your budget?\r\n        Is it public facing?\r\n        How will you manage API use?\r\n    \r\n    Azure hosting options\r\n   ![alt text](azure.PNG)\r\n    \r\n    Ways to deploy to Azure App Service\r\n        VS Code extension\r\n        Azure Portal (with Github integration)\r\n        Azure CLI\r\n        Azure Developer CLI with Bicep\r\n\r\n    Deployig to App Service with VS Code\r\n        VS code extension -\u003e Search \"Azure Tools\" -\u003e Install  \"Azure Tools\"\r\n        Select \"Create resource\" \u003e \"Create App Service Web App\"\r\n            Enter a name\r\n            Select runtime stack (Pythong 3.11)\r\n            Select tier (Free - F1)\r\n        Select \"Deploy\" and select \"api\" as the path to deploy.   \r\n\r\n    https://github.com/microsoft/Oryx\r\n        Oryx is a build tool developed by MS that is designed to simplify the process of building and deploying web applications to Azure App Service. Oryx supports a variety of programming languages and platforms, including .NET, Node.js, Python, PHP, and Java.\r\n\r\n        When you deploy your application to Azure App Service using Oryx, here is what happens:\r\n            Oryx scans your application's source code to detect the programming language and platform used by your application. It uses this information to select the appropriate buildpack for your application.\r\n            \r\n            The buildpack contains the tools and scripts needed to build and package your application for deployment. Oryx uses the selected buildpack to create a runtime environment for your application.\r\n\r\n            Oryx compiles and packages your application according to the requirements of the buildpack. This may involve running commands such as npm install to install dependencies, compiling source code into binaries, or creating an executable JAR file.\r\n\r\n            Once the application has been compiled and packaged, Oryx creates a Docker image that contains your application and its runtime environment. This Docker image is then deployed to Azure App Service.\r\n            \r\n            Throughout the deployment process, Oryx performs various optimizations to ensure that project is deployed efficiently and effectively. For example, Oryx uses caching to speed up subsequent builds and deploys, and can automatically detect changes in your project's source code and dependencies to trigger new builds.\r\n\r\n            Overall, using Oryx to deploy your project to Azure App Service simplifies the deployment process and ensures that your project is running in a consistent environment optimized for its specific requirements.      \r\n\r\n    When you deploy a Python project to Azure App Service using Oryx, the following happens:\r\n        Oryx detects and selects the appropriate buildpack for your project.\r\n\r\n        Oryx installs the required Python runtime and dependencies based on the requirements.txt. It may also run other setup tasks such as creating a virtual environment for your project.\r\n\r\n        Oryx builds your Python project and packages it as a wheel (.whl) or egg file, which can be installed in another environment. If your project includes static files or other assets, Oryx also collects these files and prepares them for deployment.\r\n\r\n        Oryx creates a Docker image that contains your Python project, its dependencies, and any assets or static files. This Docker image is then deployed to Azure App Service.\r\n\r\n        Once the Docker image is deployed, Azure App Service starts a container based on the image and your Python project is up and running.\r\n        \r\n    When you deploy to app service, MS tool oryx builds a Docerr image, it also does try to auto start an app if it's Django or flask but it doesn't understand fast API, we will tell it how to start a fast API app.\r\n        Customizing App Service for FastAPI\r\n            App Service doesn't yet know how to automatically run FastAPI apps, so we must tell it.\r\n            Either use the portal\r\n                Select \"Settings\" \u003e \"Configuration\" in left nav, then select \"General settings\" tab.\r\n                In \"Startup Command\" field, enter\r\n                    python3 -m uvicorn main:app --host 0.0.0.0\r\n                        python3 -m gunicorn main:app (it's not working)\r\n                Save and wait for server to restart.\r\n            Or use the Azure CLI\r\n                az webapp config set --resource-group \u003cresource-group\u003e --name \u003capp-name\u003e --startup-file \"python -m gunicorn main:app\"    \r\n\r\n    ERROR: If you see error  \":( Application Error ..\", \r\n        Tried to  change the service plan to B2, plan Free F1 or Basic B1 won't work - Still Error\r\n        Then change the command to \"python3 -m uvicorn main:app --host 0.0.0.0\" - it works \r\n\r\nMore API Examples\r\n    FastAPI + API Management\r\n        Azure API Management provides features of a public API: subscription keys, rate limiting, IP blocking, etc.\r\n        https://github.com/pamelafox/fastapi-azure-function-apim\r\n\r\n    FastAPI + CDN\r\n        Azure CDN provides a global netowrk of servers to cache your API responses.\r\n        https://github.com/pamelafox/staticmaps-function\r\n\r\n    FastAPI + scikitleran\r\n        A parameterized API based on a sklearn model.\r\n        https://github.com/pamelafox/scikitlearn-model-to-fastapi-app\r\n\r\n![alt text](fastapi_azure.PNG)\r\n       \r\nNext\r\n\r\n    PostgreSQL - https://github.com/mkader/postgresql\r\n    \r\n    Writing Django Apps Django framework  - https://github.com/mkader/python_django_postgresql_azure_app\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmkader%2Fpyday","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmkader%2Fpyday","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmkader%2Fpyday/lists"}