Get up and running with Akron ORM in minutes. Build your first database application with this step-by-step guide.
In this quick start guide, you'll build a simple blog application using Akron ORM. We'll cover database setup, table creation, and basic CRUD operations.
First, let's create a new directory for our blog application:
Akron ready!
Create blog_app.py and define your data models using Pydantic:
Run the script to create your database:
Creating database tables... ā Database tables created successfully! Blog application initialized!
Let's add some sample data to our blog application:
Run the updated script:
Creating database tables... ā Database tables created successfully! Adding sample data... ā Users created ā Posts created Sample data added successfully! Blog application ready!
Now let's add functions to query and display our blog data:
Run the complete application:
Creating database tables...
ā Database tables created successfully!
Adding sample data...
ā Users created
ā Posts created
Sample data added successfully!
==================================================
BLOG STATISTICS
==================================================
Total Users: 2
Total Posts: 3
Published Posts: 2
Draft Posts: 1
==================================================
USERS
==================================================
[1] alice (Alice Johnson)
Email: alice@example.com
Status: Active
Joined: 2024-01-15
[2] bob (Bob Smith)
Email: bob@example.com
Status: Active
Joined: 2024-01-15
==================================================
PUBLISHED POSTS
==================================================
[1] Welcome to My Blog
Author: alice
Status: ā Published
Created: 2024-01-15 10:30
Content: This is my first post using Akron ORM! It's amazing how easy it is to work with databases.
[2] Database Magic with Akron
Author: bob
Status: ā Published
Created: 2024-01-15 10:30
Content: Akron ORM makes database operations so simple. No more complex SQL queries!
==================================================
SEARCH RESULTS FOR: 'Akron'
==================================================
[1] Welcome to My Blog by alice
This is my first post using Akron ORM! It's amazing how easy it is to work with databases.
[2] Database Magic with Akron by bob
Akron ORM makes database operations so simple. No more complex SQL queries!
Blog application demo complete!Let's add functions to update and delete blog data:
Run the complete demo:
Creating database tables... ā Database tables created successfully! Adding sample data... ā Users created ā Posts created Sample data added successfully! ================================================== BLOG STATISTICS ================================================== Total Users: 2 Total Posts: 3 Published Posts: 2 Draft Posts: 1 ============================================================ INTERACTIVE CRUD OPERATIONS DEMO ============================================================ Creating new post: 'My Python Journey'... ā Post 'My Python Journey' created successfully! Updating post 4... ā Post 4 updated successfully! Title: My Python Journey Published: False Updated: 2024-01-15 10:30:45.123456 Publishing post 4... ā Post 'My Python Journey' published successfully! ================================================== BLOG STATISTICS ================================================== Total Users: 2 Total Posts: 4 Published Posts: 3 Draft Posts: 1 Deleting post 4... ā Post 'My Python Journey' deleted successfully! Final statistics after cleanup: ================================================== BLOG STATISTICS ================================================== Total Users: 2 Total Posts: 3 Published Posts: 2 Draft Posts: 1 ============================================================ ā Quick Start Demo Complete! ============================================================ Next steps: ⢠Try different database types (MySQL, PostgreSQL, MongoDB) ⢠Explore the CLI commands ⢠Check out the full API documentation ⢠Build your own application!
Akron also provides a powerful CLI for database operations. Let's explore some commands:
Database Schema (SQLite):
=====================================
āāā users
ā āāā id (INTEGER)
ā āāā username (TEXT)
ā āāā email (TEXT)
ā āāā full_name (TEXT)
ā āāā is_active (INTEGER)
ā āāā created_at (TEXT)
āāā posts
ā āāā id (INTEGER)
ā āāā title (TEXT)
ā āāā content (TEXT)
ā āāā author_id (INTEGER)
ā āāā published (INTEGER)
ā āāā created_at (TEXT)
ā āāā updated_at (TEXT)
āāā comments
āāā id (INTEGER)
āāā post_id (INTEGER)
āāā author_name (TEXT)
āāā content (TEXT)
āāā created_at (TEXT)
ā User added successfully
ā Table 'comments' created successfullyThe beauty of Akron is that you can use the same code with different databases. Just change the connection string:
Your models and operations work identically across all databases:
Here's the complete code for your blog application:
You've successfully built your first Akron application! You now know how to: