1- # 🚀 Ormax ORM — Fastest Async ORM for Python
1+
2+ # 🚀 Ormax ORM — The Fastest Async ORM for Python
23
34[ ![ Python Version] ( https://img.shields.io/badge/python-3.7%2B-blue )] ( https://www.python.org/downloads/ )
45[ ![ License] ( https://img.shields.io/badge/license-MIT-green )] ( LICENSE )
56[ ![ Async] ( https://img.shields.io/badge/async-await-brightgreen )] ( https://docs.python.org/3/library/asyncio.html )
67
7- > ** Ormax ORM** — The ** fastest** , most secure, and feature-rich ** asynchronous ORM** for Python.
8- > Optimized for ** high-performance** database access in modern web apps, APIs, and microservices.
9- > Supports ** MariaDB, MySQL, PostgreSQL, SQLite3, Microsoft SQL Server, Oracle Database, Amazon Aurora** .
8+ > ** Ormax ORM** is a ** high-performance** , ** secure** , and ** feature-rich** asynchronous Object-Relational Mapping (ORM) library for Python. Built for modern web applications, APIs, and microservices, Ormax delivers ** unmatched speed** and supports multiple databases, including ** MariaDB** , ** MySQL** , ** PostgreSQL** , ** SQLite3** , ** Microsoft SQL Server** , ** Oracle** , and ** Amazon Aurora** .
109
1110---
1211
13- ## 🌟 Why Ormax ORM?
12+ ## 🌟 Why Choose Ormax ORM?
1413
15- * ** 🚀 Fastest ORM in Python ** — Benchmark-proven speed beating other popular ORMs.
16- * ** 🔌 Multi-Database Support** — MariaDB, MySQL, PostgreSQL, SQLite3, MSSQL, Oracle, Aurora.
17- * ** ⚡ Fully Async ** — Built with ` asyncio ` for extreme performance.
18- * ** 🛡️ Secure by Design** — Protection against SQL injection & strong input validation .
19- * ** 📦 Easy to Use ** — Simple syntax inspired by Django ORM, but fully async.
20- * ** 🔗 Relationship Support ** — ForeignKey, reverse relations, and advanced querying .
21- * ** 💾 Connection Pooling** — Optimized database connection management.
22- * ** 💡 Advanced QuerySet** — ` select_related ` , ` prefetch_related ` , chaining filters, pagination .
23- * ** 📊 Bulk Operations ** — Create, update, delete multiple rows efficiently .
24- * ** 🔄 Transaction Support ** — ACID-compliant transactions .
14+ - ** 🚀 Blazing Fast ** : Up to ** 2× faster ** than other popular ORMs like SQLAlchemy and Tortoise ORM (see [ Benchmarks ] ( #-benchmarks ) ) .
15+ - ** 🔌 Multi-Database Support** : Seamlessly works with MariaDB, MySQL, PostgreSQL, SQLite3, MSSQL, Oracle, and Aurora.
16+ - ** ⚡ Fully Asynchronous ** : Built on ` asyncio ` for optimal performance in async applications .
17+ - ** 🛡️ Secure by Design** : Robust input validation and protection against SQL injection .
18+ - ** 📦 Intuitive API ** : Inspired by Django ORM, but optimized for async workflows with a simple, Pythonic syntax .
19+ - ** 🔗 Advanced Relationships ** : Supports ` ForeignKey ` , reverse relationships, ` select_related ` , and ` prefetch_related ` .
20+ - ** 💾 Connection Pooling** : Efficient connection management for high-concurrency workloads .
21+ - ** 📊 Powerful QuerySet** : Chaining filters, annotations, aggregations, and bulk operations .
22+ - ** 🔄 Transaction Support ** : ACID-compliant transactions for reliable data operations .
23+ - ** 🛠️ Flexible Field Types ** : Comprehensive field types like ` CharField ` , ` JSONField ` , ` UUIDField ` , and more .
2524
2625---
2726
28- ## 📈 Benchmark — Fastest Python ORM
27+ ## 📈 Benchmarks
2928
30- According to independent benchmarks, ** Ormax ORM** is ** up to 2× faster ** than traditional ORMs like SQLAlchemy and Tortoise ORM when performing async CRUD operations .
29+ Ormax ORM consistently outperforms other Python ORMs in async CRUD operations, making it ideal for high-performance applications .
3130
32- | ORM | Insert 10k rows | Select 10k rows | Update 10k rows |
33- | ------------- | --------------- | --------------- | --------------- |
31+ | ORM | Insert 10k Rows | Select 10k Rows | Update 10k Rows |
32+ | --------------- | ----------------- | ----------------- | ----------------- |
3433| ** Ormax ORM** | ** 0.82s** | ** 0.65s** | ** 0.78s** |
3534| Tortoise ORM | 1.45s | 1.10s | 1.50s |
3635| SQLAlchemy | 1.60s | 1.25s | 1.62s |
3736
38- > See full benchmark results in our [ documentation ] ( docs/benchmark.md ) .
37+ > Full benchmark details available in [ docs/benchmark.md ] ( docs/benchmark.md ) .
3938
4039---
4140
4241## 📦 Installation
4342
43+ Install Ormax ORM using pip:
44+
4445``` bash
4546pip install ormax
4647```
@@ -53,12 +54,12 @@ cd ormax
5354pip install -e .
5455```
5556
56- ---
57+ ### Dependencies
5758
58- ## 🛠️ Dependencies
59+ Depending on your database, install the required async driver:
5960
6061``` bash
61- # For MySQL/MariaDB
62+ # For MySQL/MariaDB/Amazon Aurora
6263pip install aiomysql
6364
6465# For PostgreSQL
@@ -78,10 +79,14 @@ pip install async-oracledb
7879
7980## 🚀 Quick Start
8081
82+ Get started with Ormax in just a few lines of code:
83+
8184``` python
85+ import asyncio
8286from ormax import Database, Model
83- from ormax.fields import *
87+ from ormax.fields import AutoField, CharField, ForeignKeyField
8488
89+ # Define models
8590class Author (Model ):
8691 id = AutoField()
8792 name = CharField(max_length = 100 )
@@ -91,22 +96,248 @@ class Book(Model):
9196 title = CharField(max_length = 200 )
9297 author = ForeignKeyField(' Author' , related_name = ' books' )
9398
99+ # Initialize database
94100db = Database(" sqlite:///example.db" )
95- await db.connect()
96- db.register_model(Author, Book)
97- await db.create_tables()
98101
99- author = await Author.create(name = " J.K. Rowling" )
100- book = await Book.create(title = " Harry Potter" , author = author)
102+ async def main ():
103+ # Connect to database and register models
104+ await db.connect()
105+ db.register_model(Author)
106+ db.register_model(Book)
107+ await db.create_tables()
108+
109+ # Create instances
110+ author = await Author.create(name = " J.K. Rowling" )
111+ book = await Book.create(title = " Harry Potter" , author = author)
112+
113+ # Query data
114+ books = await Book.objects().filter(author = author).all()
115+ print (books)
116+
117+ # Run the async application
118+ asyncio.run(main())
101119```
102120
103121---
104122
123+ ## 🛠️ Key Features
124+
125+ ### 1. ** Model Definition**
126+ Define database models using a clean, class-based syntax. Ormax supports a wide range of field types for flexible data modeling.
127+
128+ ``` python
129+ from ormax import Model
130+ from ormax.fields import *
131+
132+ class User (Model ):
133+ id = AutoField()
134+ username = CharField(max_length = 50 , unique = True )
135+ email = EmailField()
136+ created_at = DateTimeField(auto_now_add = True )
137+ settings = JSONField(default = {})
138+ ```
139+
140+ ### 2. ** Supported Field Types**
141+ Ormax provides a comprehensive set of field types, each with built-in validation:
142+
143+ - ** Basic Types** : ` CharField ` , ` TextField ` , ` IntegerField ` , ` BigIntegerField ` , ` SmallIntegerField ` , ` FloatField ` , ` DecimalField ` , ` BooleanField `
144+ - ** Date/Time** : ` DateTimeField ` , ` DateField ` , ` TimeField `
145+ - ** Specialized** : ` EmailField ` , ` URLField ` , ` UUIDField ` , ` IPAddressField ` , ` SlugField ` , ` JSONField ` , ` BinaryField `
146+ - ** Auto-Incrementing** : ` AutoField ` , ` BigAutoField ` , ` SmallAutoField `
147+ - ** Relationships** : ` ForeignKeyField ` (with ` related_name ` and ` on_delete ` options)
148+ - ** Positive Variants** : ` PositiveIntegerField ` , ` PositiveSmallIntegerField `
149+
150+ Example:
151+ ``` python
152+ class Post (Model ):
153+ id = AutoField()
154+ title = CharField(max_length = 200 )
155+ content = TextField(max_length = 5000 )
156+ slug = SlugField(unique = True )
157+ views = PositiveIntegerField(default = 0 )
158+ metadata = JSONField()
159+ ```
160+
161+ ### 3. ** QuerySet API**
162+ Ormax's ` QuerySet ` provides a powerful and chainable interface for querying data:
163+
164+ ``` python
165+ # Filter and order
166+ posts = await Post.objects().filter(views__gt = 100 ).order_by(" -created_at" ).all()
167+
168+ # Select specific fields
169+ titles = await Post.objects().values_list(" title" , flat = True )
170+
171+ # Aggregations
172+ total_views = await Aggregation.sum(Post.objects(), " views" )
173+ avg_views = await Aggregation.avg(Post.objects(), " views" )
174+
175+ # Relationships
176+ author = await Author.objects().get(id = 1 )
177+ books = await author.books.all() # Reverse relationship
178+ ```
179+
180+ ### 4. ** Relationships**
181+ Ormax supports ` ForeignKeyField ` for forward and reverse relationships:
182+
183+ ``` python
184+ # Forward relationship
185+ book = await Book.objects().get(id = 1 )
186+ author = await book.author.get() # Access related Author
187+
188+ # Reverse relationship
189+ author = await Author.objects().get(id = 1 )
190+ books = await author.books.all() # Get all Books by this Author
191+ ```
192+
193+ ### 5. ** Bulk Operations**
194+ Efficiently create, update, or delete multiple records:
195+
196+ ``` python
197+ # Bulk create
198+ await Post.bulk_create([
199+ {" title" : " Post 1" , " content" : " Content 1" },
200+ {" title" : " Post 2" , " content" : " Content 2" }
201+ ], batch_size = 100 )
202+
203+ # Bulk update
204+ await Post.objects().filter(views__lt = 10 ).update(views = 0 )
205+ ```
206+
207+ ### 6. ** Transactions**
208+ Use transactions for atomic operations:
209+
210+ ``` python
211+ async with db.transaction():
212+ author = await Author.create(name = " New Author" )
213+ await Book.create(title = " New Book" , author = author)
214+ ```
215+
216+ ### 7. ** Connection Pooling**
217+ Ormax uses connection pooling for efficient database access, optimized for high-concurrency workloads.
218+
219+ ### 8. ** Security Features**
220+ - ** Input Sanitization** : Prevents SQL injection with ` sanitize_input ` and ` sanitize_dict ` .
221+ - ** Validation** : Robust field validation ensures data integrity.
222+ - ** Secure Password Handling** : Functions like ` hash_password ` and ` verify_password ` for secure authentication.
223+
224+ ---
225+
226+ ## 📚 Advanced Usage
227+
228+ ### Custom QuerySet Methods
229+ Extend ` QuerySet ` for custom query logic:
230+
231+ ``` python
232+ class CustomQuerySet (QuerySet ):
233+ async def by_category (self , category : str ):
234+ return self .filter(category = category)
235+
236+ class Post (Model ):
237+ objects = CustomQuerySet.as_manager()
238+ category = CharField(max_length = 50 )
239+
240+ # Usage
241+ posts = await Post.objects().by_category(" news" ).all()
242+ ```
243+
244+ ### Raw SQL Queries
245+ Execute raw SQL for complex queries:
246+
247+ ``` python
248+ results = await Post.objects().raw(" SELECT * FROM post WHERE views > %s " , (100 ,)).execute()
249+ ```
250+
251+ ### Caching
252+ Use ` memoize_async ` or ` cached_property ` for performance optimization:
253+
254+ ``` python
255+ from ormax.utils import memoize_async
256+
257+ @memoize_async (maxsize = 100 )
258+ async def get_user_stats (user_id : int ):
259+ return await User.objects().filter(id = user_id).values(" stats" )
260+ ```
261+
262+ ### Logging and Performance Monitoring
263+ Ormax includes built-in logging and performance monitoring:
264+
265+ ``` python
266+ from ormax.utils import setup_logging, PerformanceMonitor
267+
268+ setup_logging(level = " DEBUG" )
269+ monitor = PerformanceMonitor()
270+
271+ async def some_operation ():
272+ with monitor.record(" operation" ):
273+ await Post.objects().all()
274+ ```
275+
276+ ---
277+
278+ ## 🔧 Configuration
279+
280+ ### Database Connection
281+ Create a ` Database ` instance with a connection string:
282+
283+ ``` python
284+ # SQLite
285+ db = Database(" sqlite:///example.db" )
286+
287+ # PostgreSQL
288+ db = Database(" postgresql://user:password@localhost:5432/dbname" )
289+
290+ # MySQL/MariaDB
291+ db = Database(" mysql://user:password@localhost:3306/dbname" )
292+ ```
293+
294+ ### Model Registration
295+ Register models before use:
296+
297+ ``` python
298+ db.register_model(Author)
299+ db.register_model(Book)
300+ await db.create_tables()
301+ ```
302+
303+ ---
304+
305+ ## 📜 API Reference
306+
307+ ### Core Classes
308+ - ** Database** : Manages connections, model registration, and table creation.
309+ - ** Model** : Base class for defining database models.
310+ - ** QuerySet** : Chainable query interface for filtering, ordering, and aggregating.
311+ - ** Field** : Base class for all field types, with validation and SQL generation.
312+ - ** RelationshipManager** : Handles forward and reverse relationships.
313+
314+ ### Utility Functions
315+ - ** sanitize_input** : Prevents SQL injection by sanitizing input.
316+ - ** hash_password** / ** verify_password** : Secure password handling.
317+ - ** generate_slug** : Creates URL-friendly slugs.
318+ - ** json_dumps** / ** json_loads** : Custom JSON serialization for ORM types.
319+ - ** retry_async** / ** timeout_async** : Decorators for reliable async operations.
320+
321+ ---
322+
105323## 🔍 SEO Keywords
324+ ` Fastest Python ORM ` , ` Async Python ORM ` , ` Best Python ORM 2025 ` , ` High Performance ORM ` , ` Python asyncio ORM ` , ` PostgreSQL Async ORM ` , ` MySQL Async ORM ` , ` Secure Python ORM ` , ` ORM for Microservices ` , ` Python Database Library `
325+
326+ ---
327+
328+ ## 🤝 Contributing
329+ Contributions are welcome! Please follow these steps:
330+ 1 . Fork the repository.
331+ 2 . Create a feature branch (` git checkout -b feature/YourFeature ` ).
332+ 3 . Commit your changes (` git commit -m "Add YourFeature" ` ).
333+ 4 . Push to the branch (` git push origin feature/YourFeature ` ).
334+ 5 . Open a pull request.
335+
336+ ---
106337
107- ` Fastest Python ORM ` , ` Async Python ORM ` , ` Best Python ORM 2025 ` , ` High Performance ORM ` ,
108- ` Python asyncio ORM` , ` PostgreSQL Async ORM ` , ` MySQL Async ORM ` , ` Secure Python ORM ` .
338+ ## 📄 License
339+ Ormax ORM is licensed under the [ MIT License ] ( LICENSE ) .
109340
110341---
111342
112- ** Made with ❤️ for Python developers who value speed and simplicity .**
343+ ** Made with ❤️ for Python developers who value speed, simplicity, and reliability .**
0 commit comments