<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: victor wangari</title>
    <description>The latest articles on DEV Community by victor wangari (@victor_wangari_6e6143475e).</description>
    <link>https://dev.to/victor_wangari_6e6143475e</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1555849%2F51873e9b-a0fe-4a07-beea-e6a159e828c8.png</url>
      <title>DEV Community: victor wangari</title>
      <link>https://dev.to/victor_wangari_6e6143475e</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/victor_wangari_6e6143475e"/>
    <language>en</language>
    <item>
      <title>PYTHON FLASK</title>
      <dc:creator>victor wangari</dc:creator>
      <pubDate>Tue, 18 Jun 2024 12:09:48 +0000</pubDate>
      <link>https://dev.to/victor_wangari_6e6143475e/python-flask-4c2a</link>
      <guid>https://dev.to/victor_wangari_6e6143475e/python-flask-4c2a</guid>
      <description>&lt;p&gt;*&lt;em&gt;What is flask *&lt;/em&gt;&lt;br&gt;
Flask is micro web framework written in python.&lt;br&gt;
It is designed to be lightweight and easy to use, providing the essential tools needed to build web applications, while allowing developers the flexibility to add additional libraries and tools  as required.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Features of Flask&lt;/strong&gt; &lt;br&gt;
1.Simplicity and flexibility:Flask is simple to set up and use. It gives developers the freedom to choose the components they want to use, making it flexible for a wide range of applications.&lt;/p&gt;

&lt;p&gt;2.Lightweight:As a micro-framework, Flask comes with a small core and essential functionalities. Additional features can be added using extensions.&lt;/p&gt;

&lt;p&gt;3.Modular Design:Flask's modular design allows for the inclusion of extensions for added functionality, such as database integration, form validation, and authentication.&lt;/p&gt;

&lt;p&gt;4.Built-in Development Server and Debugger: Flask includes a built-in development server and a debugger, which help developers test and debug their applications.&lt;/p&gt;

&lt;p&gt;5.Jinja2 Templating: Flask uses Jinja2 templating engine, which enables developers to use templates to dynamically generate HTML.&lt;/p&gt;

&lt;p&gt;6.RESTful Request Dispatching:Flask supports RESTful request dispatching, making it a good choice for developing APIs.&lt;/p&gt;

&lt;p&gt;7.WSGI Compliance:Flask is WSGI compliant, which means it can be deployed on any WSGI-compatible web server.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Common Extensions used in flask&lt;/strong&gt;&lt;br&gt;
Flask does not come with many built-in features but relies on extensions to provide additional functionality. Some popular Flask extensions include:&lt;br&gt;
 &lt;strong&gt;.Flask-SQLAlchemy:&lt;/strong&gt;Adds SQLAlchemy support for the database operations.&lt;br&gt;
 &lt;strong&gt;Flask-WTF:&lt;/strong&gt;Integrates WTForms for form handling and validations.&lt;br&gt;
 &lt;strong&gt;Flask-Login:&lt;/strong&gt;Manages users session and authentication.&lt;br&gt;
 &lt;strong&gt;Flask-Migrate:&lt;/strong&gt;Handles database migrations using Alembic.&lt;/p&gt;

&lt;p&gt;to be continued....&lt;/p&gt;

</description>
    </item>
    <item>
      <title>PYTHON P-3 PROJECT</title>
      <dc:creator>victor wangari</dc:creator>
      <pubDate>Mon, 10 Jun 2024 17:52:15 +0000</pubDate>
      <link>https://dev.to/victor_wangari_6e6143475e/python-p-3-project-250o</link>
      <guid>https://dev.to/victor_wangari_6e6143475e/python-p-3-project-250o</guid>
      <description>&lt;p&gt;==&amp;gt;Creating a URL shortener is a great project that leverages databases, ORMs, and database diagrams effectively. Here’s how you can approach building a URL shortener using Python with SQLite3 and SQLAlchemy.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Project: URL Shortener&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Features&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;em&gt;Shorten URLs&lt;/em&gt;

&lt;ul&gt;
&lt;li&gt;Accept long URLs and generate short URLs&lt;/li&gt;
&lt;li&gt;Ensure unique short URLs
-Optionally, allow custom short URLs&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;2.&lt;em&gt;Redirect Short URLs&lt;/em&gt; &lt;br&gt;
   -Redirect users to the original URL when &lt;br&gt;
    they visit the short URL&lt;/p&gt;

&lt;p&gt;3.&lt;em&gt;URL Analytics&lt;/em&gt;&lt;br&gt;
   -Track the number of visits to each short &lt;br&gt;
   URL.&lt;/p&gt;

&lt;p&gt;4.&lt;em&gt;User Management(OPTIONAL)&lt;/em&gt;&lt;br&gt;
   -Allow users to register and manage their &lt;br&gt;
   short URLs .&lt;br&gt;
   -Implement user authentication(login/logout)&lt;/p&gt;

&lt;p&gt;5.&lt;em&gt;Database Diagram&lt;/em&gt;&lt;br&gt;
   -Visual representation of the database &lt;br&gt;
   schema using tools like &lt;strong&gt;dbdiagram.io&lt;/strong&gt; or &lt;br&gt;
   &lt;strong&gt;SQLAlchemy's&lt;/strong&gt; build-in features&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Steps to Implement&lt;/strong&gt;&lt;br&gt;
1.&lt;em&gt;Setup the Project&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;-Create a new directory for your project&lt;br&gt;
  -Set up a virtual environment&lt;br&gt;
  -Install necessary dependencies: flask, &lt;br&gt;
  ** sqlalchemy*&lt;em&gt;, **flask_sqlalchemy&lt;/em&gt;&lt;em&gt;, &lt;br&gt;
  **flask_migrate&lt;/em&gt;*&lt;/p&gt;

&lt;p&gt;2.&lt;em&gt;Database Design&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;-Define the database schema using SQLAlchemy &lt;br&gt;
  models&lt;br&gt;
 -Create tables for URLs and Users (if user &lt;br&gt;
  management is implemented)&lt;/p&gt;

&lt;p&gt;3.&lt;em&gt;Database Diagram&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;-Use a tool like dbdiagram.io to create a &lt;br&gt;
   visual representation of your database &lt;br&gt;
   schema&lt;br&gt;
  -Alternatively, use SQLAlchemy to generate &lt;br&gt;
   the schema and visualize it using a library &lt;br&gt;
   like &lt;strong&gt;ERAlchemy&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;4.&lt;em&gt;URL Shortening Logic&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;-Implement logic to generate short URLs&lt;br&gt;
  -Handle URL collisions to ensure unique short &lt;br&gt;
   URLs&lt;/p&gt;

&lt;p&gt;5.Redirect Logic__&lt;/p&gt;

&lt;p&gt;-Implement route to handle redirection from &lt;br&gt;
   short URLs to original URLs&lt;/p&gt;

&lt;p&gt;6.&lt;em&gt;Analytics&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;-Track and store analytics data such as &lt;br&gt;
    visit counts and access dates&lt;/p&gt;

&lt;p&gt;7.&lt;em&gt;User Management (Optional)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;-Implement user registration and login using &lt;br&gt;
    Flask-Login or Flask-Security&lt;br&gt;
   -Allow users to manage their short URLs&lt;/p&gt;

&lt;p&gt;8.&lt;em&gt;Testing and Deployment&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;-Write unit tests for your application&lt;br&gt;
  -Deploy the application using a service like &lt;br&gt;
   Heroku or AWS&lt;/p&gt;

</description>
    </item>
    <item>
      <title>SQL JOIN IN PYTHON</title>
      <dc:creator>victor wangari</dc:creator>
      <pubDate>Sat, 08 Jun 2024 18:43:48 +0000</pubDate>
      <link>https://dev.to/victor_wangari_6e6143475e/sql-join-in-python-3h0k</link>
      <guid>https://dev.to/victor_wangari_6e6143475e/sql-join-in-python-3h0k</guid>
      <description>&lt;p&gt;In SQL, the JOIN clause is used to combine rows from two or more tables based on a related column between them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Types of JOINs&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;1. INNER JOIN&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;An **INNER JOIN&lt;/strong&gt; returns only the rows that have matching values in both tables.&lt;br&gt;
    &lt;em&gt;SYNTAX&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT columns
FROM table1
INNER JOIN table2
ON table1.common_column = table2.common_column;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; _EXAMPLE_
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT employees.name, departments.department_name
FROM employees
INNER JOIN departments
ON employees.department_id = departments.id

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;EXPLANATIONS&lt;/em&gt;&lt;br&gt;
**This query selects all employees and their corresponding department names where there is a match between employees.department_id and departments.id.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. LEFT JOIN (or LEFT OUTER JOIN)&lt;/strong&gt;&lt;br&gt;
**A LEFT JOIN returns all rows from the left table (table1), and the matched rows from the right table (table2). If no match is found, NULL values are returned for columns from the right table.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;_SYNTAX_
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT columns
FROM table1
LEFT JOIN table2
ON table1.common_column = table2.common_column;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;_EXAMPLE_
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT employees.name, departments.department_name
FROM employees
LEFT JOIN departments
ON employees.department_id = departments.id;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;em&gt;EXPLANATIONS&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;**This query selects all employees, including those who do not belong to any department. For employees without a department, department_name will be NULL.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3.RIGHT JOIN (or RIGHT OUTER JOIN)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;**A RIGHT JOIN returns all rows from the right table (table2), and the matched rows from the left table (table1). If no match is found , NULL values are returned for columns from the left table.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;_SYNTAX_
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT columns
FROM table1
RIGHT JOIN table2
ON table1.common_column = table2.common_column;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;em&gt;EXAMPLE&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT employees.name, departments.department_name
FROM employees
RIGHT JOIN departments
ON employees.department_id = departments.id;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;_EXPLANATIONS_
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;**This query selects all departments, including those without any employees. For departments without employees, name will be NULL.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4.FULL JOIN (or FULL OUTER JOIN)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;**A FULL JOIN returns all rows when there is a match in either left (table1) or right (table2) table. Rows without a match in one of the tables will have NULLs for columns from that table.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;SYNTAX&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT columns
FROM table1
FULL JOIN table2
ON table1.common_column = table2.common_column;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;EXAMPLE&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT employees.name, departments.department_name
FROM employees
FULL JOIN departments
ON employees.department_id = departments.id;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;_EXPLANATIONS_
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;This query selects all employees and departments, showing NULLs where there is no match.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;5.CROSS JOIN&lt;/strong&gt;&lt;br&gt;
**A CROSS JOIN returns the Cartesian product of the two tables, i.e., it returns all possible combinations of rows from the tables.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;_SYNTAX_
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT columns
FROM table1
CROSS JOIN table2;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;_EXAMPLE_
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT employees.name, departments.department_name
FROM employees
CROSS JOIN departments;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;em&gt;EXPLANATIONS&lt;/em&gt;&lt;br&gt;
**This query combines each employee with each department, resulting in a large number of rows.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6.SELF JOIN&lt;/strong&gt;&lt;br&gt;
**A SELF JOIN is a regular join, but the table is joined with itself.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;SYNTAX&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT a.columns, b.columns
FROM table a, table b
WHERE a.common_column = b.common_column;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;EXAMPLE&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT e1.name AS Employee, e2.name AS Manager
FROM employees e1
INNER JOIN employees e2
ON e1.manager_id = e2.id;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Key Points:&lt;/strong&gt;&lt;br&gt;
 i. &lt;strong&gt;JOIN Conditions:&lt;/strong&gt;The ON clause specifies the condition for the join, typically matching a column from one table with a column from another table.&lt;br&gt;
ii. &lt;strong&gt;Aliases:&lt;/strong&gt;Using table aliases (e.g., e1, e2 in the SELF JOIN example) can make the query more readable and manageable, especially for self joins or when the same table is used multiple times.&lt;br&gt;
iii. &lt;strong&gt;NULL Handling:&lt;/strong&gt;In OUTER JOINs (LEFT, RIGHT, FULL), unmatched rows will have NULL values for the columns of the table that does not have the match.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>OBJECT-RELATIONAL MAPPING in PYTHON</title>
      <dc:creator>victor wangari</dc:creator>
      <pubDate>Thu, 06 Jun 2024 09:43:57 +0000</pubDate>
      <link>https://dev.to/victor_wangari_6e6143475e/object-relational-mapping-in-python-42pg</link>
      <guid>https://dev.to/victor_wangari_6e6143475e/object-relational-mapping-in-python-42pg</guid>
      <description>&lt;p&gt;&lt;strong&gt;KEY VOCAB&lt;/strong&gt;&lt;br&gt;
Object-Relational Mapping(ORM): A technique used to convert database records into objects in an object-oriented language.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;INTRODUCTION&lt;/strong&gt;&lt;br&gt;
**Object Relational  Mapping is way for our python programs to manage database data by "mapping" database tables to classes and instances of classes to rows  in those tables.&lt;br&gt;
**There is no special programming magic to an ORM — it is simply a manner in which we implement the code that connects our Python program to our database. For example, you can use code like this to connect your Python program to a given database:&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;db_connection = sqlite3.connect('db/my_database.db')&lt;br&gt;
db_cursor = db_connection.cursor()&lt;br&gt;
*&lt;/em&gt;&lt;br&gt;
An ORM is really just a concept. It is a design pattern , a conventional way for us to organize our program when we want those programs to connect to a database.The conventional is this :&lt;br&gt;
When "mapping" our program to a database, we equate classes with database tables, and instances of those classes with table rows.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;WHY USE ORM??&lt;/strong&gt;&lt;br&gt;
.Cutting down repetitive code.&lt;br&gt;
.Implementing conventional patterns that are organized and sensical&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cutting Down on Repetition&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;As programmers , you might remember we are lazy.We don't like to repeat ourselves if we can avoid it. Repetition qualifies as a "code smell". Instead of repeating the same, or similar, code any time we want to perform common actions against our database, we can write a series of methods to abstract that behavior.&lt;br&gt;
** We can use **save()&lt;/strong&gt; method on our classes that handles the common actions if &lt;strong&gt;INSERT&lt;/strong&gt;ing data into database.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;LOGICAL DESIGN&lt;/strong&gt;&lt;br&gt;
**Another important reason to implement the ORM pattern is that it just makes sense. Telling our Python program to communicate with our database is confusing enough without each individual developer having to make their own, individual decision about how our program should talk to our database.&lt;/p&gt;

&lt;p&gt;Instead, we follow the convention: classes are mapped to or equated with tables and instances of a class are equated to table rows.&lt;/p&gt;

&lt;p&gt;If we have a Cat class, we have a cats table. Cat instances get stored as rows in the cats table.&lt;/p&gt;

&lt;p&gt;Further, we don't have to make our own potentially confusing or non-sensical decision about what kinds of methods we will build to help our classes communicate with our database. Just like the save() method we previewed above, we will learn to build a series of common, conventional methods that our programs can rely on again and again to communicate with our database.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
