
Product
Introducing Socket Firewall Enterprise: Flexible, Configurable Protection for Modern Package Ecosystems
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.
A tiny, simple ORM built on top of Pydantic.
When you need to perform simple CRUD operations with minimal code.
Offers support for PostgreSQL, MySQL, SQLite (database URL syntax is the same as in SQLAlchemy).
pip install ormantism
import ormantism
# Connect to a file database
ormantism.connect("sqlite:///my_app.db")
# Or use in-memory database for testing
ormantism.connect("sqlite://:memory:")
# MySQL
ormantism.connect("mysql://login:password@host:port/database")
# PostgresSQL
ormantism.connect("postgresql://login:password@host:port/database")
from ormantism import Base
from typing import Optional
class User(Base):
name: str
email: str
age: Optional[int] = None
class Post(Base, with_timestamps=True):
title: str
content: str
author: User
# Create a user
user = User(name="Alice", email="alice@example.com", age=30)
# The record is automatically saved to the database
# Create a post linked to the user
post = Post(title="My First Post", content="Hello World!", author=user)
# Load by ID
user = User.load(id=1)
# Load by criteria
user = User.load(name="Alice")
user = User.load(email="alice@example.com")
# Load latest post from alice@example.com
latest_post = Post.load(user_id=user.id, last_created=True)
# Load all records
users = User.load_all()
# Load with criteria
users_named_alice = User.load_all(name="Alice")
user = User.load(id=1)
user.age = 31 # Automatically saved to database
# or
user.update(age=31, email="alice.updated@example.com")
user = User.load(id=1)
user.delete()
Add automatic timestamp tracking to your models:
class Post(Base, with_timestamps=True):
title: str
content: str
This adds created_at, updated_at, and deleted_at fields. Soft deletes are used when timestamps are enabled.
class Author(Base):
name: str
class Book(Base):
title: str
author: Author
# Create records
author = Author(name="Jane Doe")
book = Book(title="My Book", author=author)
# Lazy loading - author is loaded from DB when accessed
book = Book.load(id=1)
print(book.author.name) # Database query happens here
Avoid N+1 queries by preloading relationships:
# Load book with author in a single query
book = Book.load(id=1, preload="author")
print(book.author.name) # No additional database query
# Preload nested relationships
book = Book.load(id=1, preload="author.publisher")
# Preload multiple relationships
book = Book.load(id=1, preload=["author", "category"])
from ormantism import transaction
try:
with transaction() as t:
user1 = User(name="Alice", email="alice@example.com")
user2 = User(name="Bob", email="bob@example.com")
# Both users are saved automatically
# Transaction commits when exiting the context
except Exception:
# Transaction is automatically rolled back on any exception
pass
# Load single record
user = User.load(name="Alice")
latest_user = User.load(last_created=True)
# Load multiple records
all_users = User.load_all()
users_named_alice = User.load_all(name="Alice")
# Include soft-deleted records (when using timestamps)
all_including_deleted = User.load_all(with_deleted=True)
class User(Base):
name: str
email: str
age: int = 25 # Default value
bio: Optional[str] = None # Nullable field
class Post(Base, with_timestamps=True):
title: str
content: str
# Automatically adds: created_at, updated_at, deleted_at
int, float, strOptional[T] for nullable fieldslist, dict (stored as JSON)datetime.datetimeenum.Enumclass Category(Base):
name: str
class Post(Base):
title: str
category: Category # Foreign key relationship
tags: Optional[Category] = None # Nullable relationship
Model() - Create and automatically save a new recordModel.load(**criteria) - Load single recordModel.load(last_created=True) - Load most recently created recordModel.load_all(**criteria) - Load multiple recordsModel.load(preload="relationship") - Eager load relationshipsModel.load(with_deleted=True) - Include soft-deleted recordsinstance.update(**kwargs) - Update multiple fieldsinstance.field = value - Update single field (auto-saves)instance.delete() - Delete record (soft delete if timestamps enabled)ormantism.connect(database_url) - Connect to databaseormantism.transaction() - Get transaction context managerMIT License
Contributions are welcome! Please feel free to submit a Pull Request.
FAQs
A lightweight ORM built on Pydantic for simple CRUD operations with minimal code
We found that ormantism demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.

Security News
Open source dashboard CNAPulse tracks CVE Numbering Authorities’ publishing activity, highlighting trends and transparency across the CVE ecosystem.

Product
Detect malware, unsafe data flows, and license issues in GitHub Actions with Socket’s new workflow scanning support.