GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing www.fullstackpython.com — Databases DatabasesA database is an abstraction over an operating system's file system that makes it easier for developers to build applications that create, read, update and delete persistent data.
Why are databases necessary?At a high level web applications store data and present it to users in a useful way. For example, Google stores data about roads and provides directions to get from one location to another by driving through the Maps application. Driving directions are possible because the data is stored in a structured format. Databases make structured storage reliable and fast. They also give you a mental framework for how the data should be saved and retrieved instead of having to figure out what to do with the data every time you build a new application. Databases are a concept with many implementations, including PostgreSQL, MySQL and SQLite. Non-relational databases called NoSQL data stores also exist. Learn more in the data chapter or view the table of contents for all topics.
Relational databasesThe database storage abstraction most commonly used in Python web development is sets of relational tables. Alternative storage abstractions are explained on the NoSQL page. Relational databases store data in a series of tables. Interconnections between the tables are specified as foreign keys. A foreign key is a unique reference from one row in a relational table to another row in a table, which can be the same table but is most commonly a different table. Databases storage implementations vary in complexity. SQLite, a database included with Python, creates a single file for all data per database. Other databases such as PostgreSQL, MySQL, Oracle and Microsoft SQL Server have more complicated persistence schemes while offering additional advanced features that are useful for web application data storage. These advanced features include but are not limited to:
Typically web applications start with a single database instance such as PostgreSQL with a straightforward schema. Over time the database schema evolves to a more complex structure using schema migrations and advanced features such as replication, sharding and monitoring become more useful as database utilization increases based on the application users' needs. Most common databases for Python web appsPostgreSQL and MySQL are two of the most common open source databases for storing Python web applications' data. SQLite is a database that is stored in a single file on disk. SQLite is built into Python but is only built for access by a single connection at a time. Therefore is highly recommended to not run a production web application with SQLite. PostgreSQL databasePostgreSQL is the recommended relational database for working with Python web applications. PostgreSQL's feature set, active development and stability contribute to its usage as the backend for millions of applications live on the Web today. Learn more about using PostgreSQL with Python on the PostgreSQL page. MySQL databaseMySQL is another viable open source database implementation for Python applications. MySQL has a slightly easier initial learning curve than PostgreSQL but is not as feature rich. Find out about Python applications with a MySQL backed on the dedicated MySQL page. Connecting to a database with PythonTo work with a relational database using Python, you need to use a code library. The most common libraries for relational databases are:
SQLite support is built into Python 2.7+ and therefore a separate library is not necessary. Simply "import sqlite3" to begin interfacing with the single file-based database. Object-relational MappingObject-relational mappers (ORMs) allow developers to access data from a backend by writing Python code instead of SQL queries. Each web application framework handles integrating ORMs differently. There's an entire page on object-relational mapping (ORMs) that you should read to get a handle on this subject. Database third-party servicesNumerous companies run scalable database servers as a hosted service. Hosted databases can often provide automated backups and recovery, tightened security configurations and easy vertical scaling, depending on the provider.
SQL resourcesYou may plan to use an object-relational mapper (ORM) as your main way of interacting with a database, but you should still learn the basics of SQL to create schemas and understand the SQL code generated by the ORM. The following resources can help you get up to speed on SQL if you have never previously used it.
General database resources
Databases learning checklist
What's next to get your app running?
1. Introduction
2. Development Environments
3. Data
Relational Databases
PostgreSQL
MySQL
SQLite
Object-relational Mappers
SQLAlchemy
Peewee
Django ORM
Pony ORM
NoSQL Data Stores
Redis
MongoDB
Apache Cassandra
Neo4j
Data analysis
pandas
SciPy & NumPy
Data visualization
Bokeh
d3.js
Matplotlib
Markup Languages
Markdown
reStructuredText
Oracle
4. Web Development
5. Deployment
6. DevOps
Changelog
What Full Stack Means
About the Author
Future Directions
Page Statuses
...or view the full table of contents.
Full Stack Python
Full Stack Python
is an open book that explains concepts in plain language and provides
helpful resources for those topics.
Updates via Twitter & Facebook. |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |