Skip to main content

Sway ORM

Sway ORM is a type-safe, asynchronous ORM for PostgreSQL. It uses Pydantic models, a Rust SQL compiler, and Psycopg as its native database driver.

Sway ORM began as a PostgreSQL-focused fork of Oxyde ORM by Nikita Ryzhenkov.

Requires PostgreSQL 18+ and Python 3.15+. CI tests PostgreSQL 18 and 19. Sway checks the server version when connecting. Both postgres:// and postgresql:// connection URLs are supported.

Features

Core Features

  • Pydantic v2 models with validation, type hints, and serialization.
  • Generated type stubs for models and queries, checked with mypy, pyright, and ty.
  • Familiar Model.filter() queries, joins, relationship prefetch, aggregates, and bulk operations.
  • Rust query compilation and migration planning, exposed to Python through PyO3.
  • Async query execution with Psycopg 3. Its native pool backs named connections and FastAPI lifecycle integration with db.lifespan().
  • Async transactions with nested savepoints and public transaction-depth reporting.
  • Q and F expressions, raw SQL, UNION queries, and query plans with explain().
  • Schema migrations with sway makemigrations and sway migrate. Apply pending migrations out of order when their declared dependencies are satisfied. See migration dependencies.

Built for PostgreSQL

  • Native arrays, JSONB, enums, UUIDs, and decimals, plus RETURNING and row-level locking.
  • Array and JSON lookups with contains, contained_by, and overlap.
  • Composite primary keys, NULLS NOT DISTINCT constraints, and declarative TimescaleDB hypertables.
  • Migration support for extension management, PostgreSQL advisory locks, and transactional DDL where supported.
  • LISTEN/NOTIFY subscriptions on dedicated connections with db.listen().
  • Atomic get-or-create and scan I/O statistics on PostgreSQL 19.
  • Unnamed statements for PostgreSQL and PgBouncer when the statement cache is disabled.

Installation

Install into a Python 3.15 virtual environment.

uv pip install 'sway-orm[binary]'

sway-orm includes the Python ORM and its Rust extension, sway._sway_core, and installs Psycopg and its async pool. The binary extra installs Psycopg's compiled implementation with bundled libpq on supported platforms. For free-threaded Python, install sway-orm with system libpq. The ORM import and CLI are both sway.

To build this checkout:

uv venv --python 3.15
source .venv/bin/activate
uv pip install maturin
make build-core-dev

Quick start

import asyncio
from sway import Field, Model, db
from sway.db.schema import create_tables


class User(Model):
    id: int | None = Field(default=None, db_pk=True)
    name: str
    email: str = Field(db_unique=True)
    tags: list[str] = Field(default_factory=list)

    class Meta:
        is_table = True


async def main():
    await db.init(default="postgresql://user:password@localhost:5432/app")
    try:
        connection = await db.get_connection()
        await create_tables(connection)
        await User.create(
            name="Alice", email="alice@example.com", tags=["python"]
        )
        users = await User.filter(tags__contains=["python"]).all()
        print(users)
    finally:
        await db.close()


asyncio.run(main())

For managed schema changes, run sway init, sway makemigrations, and sway migrate. See the documentation, connection guide, and contributor guide.

See the 1.1 upgrade notes for the model query API change.

License

Sway ORM is available under the MIT license. License

Metadata

Release files for sway-orm 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sway-orm 1.1.0
File Size Uploaded Provenance Actions
sway_orm-1.1.0.tar.gz 597.8 kB Without provenance Details for sway_orm-1.1.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for sway-orm 1.1.0
File Actions
sway_orm-1.1.0-cp315-cp315t-win_amd64.whl CPython 3.15 CPython 3.15 free-threading Windows x86-64 Details for sway_orm-1.1.0-cp315-cp315t-win_amd64.whl
sway_orm-1.1.0-cp315-cp315t-musllinux_1_2_x86_64.whl CPython 3.15 CPython 3.15 free-threading Linux musl 1.2+ x86-64 Details for sway_orm-1.1.0-cp315-cp315t-musllinux_1_2_x86_64.whl
sway_orm-1.1.0-cp315-cp315t-musllinux_1_2_aarch64.whl CPython 3.15 CPython 3.15 free-threading Linux musl 1.2+ ARM64 Details for sway_orm-1.1.0-cp315-cp315t-musllinux_1_2_aarch64.whl
sway_orm-1.1.0-cp315-cp315t-manylinux_2_28_x86_64.whl CPython 3.15 CPython 3.15 free-threading Linux glibc 2.28+ x86-64 Details for sway_orm-1.1.0-cp315-cp315t-manylinux_2_28_x86_64.whl
sway_orm-1.1.0-cp315-cp315t-manylinux_2_28_aarch64.whl CPython 3.15 CPython 3.15 free-threading Linux glibc 2.28+ ARM64 Details for sway_orm-1.1.0-cp315-cp315t-manylinux_2_28_aarch64.whl
sway_orm-1.1.0-cp315-cp315t-macosx_11_0_arm64.whl CPython 3.15 CPython 3.15 free-threading macOS 11.0+ ARM64 Details for sway_orm-1.1.0-cp315-cp315t-macosx_11_0_arm64.whl
sway_orm-1.1.0-cp315-cp315-win_amd64.whl CPython 3.15 CPython 3.15 Windows x86-64 Details for sway_orm-1.1.0-cp315-cp315-win_amd64.whl
sway_orm-1.1.0-cp315-cp315-musllinux_1_2_x86_64.whl CPython 3.15 CPython 3.15 Linux musl 1.2+ x86-64 Details for sway_orm-1.1.0-cp315-cp315-musllinux_1_2_x86_64.whl
sway_orm-1.1.0-cp315-cp315-musllinux_1_2_aarch64.whl CPython 3.15 CPython 3.15 Linux musl 1.2+ ARM64 Details for sway_orm-1.1.0-cp315-cp315-musllinux_1_2_aarch64.whl
sway_orm-1.1.0-cp315-cp315-manylinux_2_28_x86_64.whl CPython 3.15 CPython 3.15 Linux glibc 2.28+ x86-64 Details for sway_orm-1.1.0-cp315-cp315-manylinux_2_28_x86_64.whl
sway_orm-1.1.0-cp315-cp315-manylinux_2_28_aarch64.whl CPython 3.15 CPython 3.15 Linux glibc 2.28+ ARM64 Details for sway_orm-1.1.0-cp315-cp315-manylinux_2_28_aarch64.whl
sway_orm-1.1.0-cp315-cp315-macosx_11_0_arm64.whl CPython 3.15 CPython 3.15 macOS 11.0+ ARM64 Details for sway_orm-1.1.0-cp315-cp315-macosx_11_0_arm64.whl

Total release size: 33.1 MB

Release files / sway_orm-1.1.0.tar.gz

Download URL sway_orm-1.1.0.tar.gz
Size 597.8 kB
Tags Source
SHA-256 checksum
How to use checksums
94b0616b784e6c9521fbb19c7a5208c31505c070576a935213ced90b7672f65e
BLAKE2b-256 checksum
How to use checksums
c90d679f5cd98c6d6ceeef432b5d87061b6552143a266e36166f71922cdf973b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / sway_orm-1.1.0-cp315-cp315t-win_amd64.whl

Download URL sway_orm-1.1.0-cp315-cp315t-win_amd64.whl
Size 2.0 MB
Tags CPython 3.15 CPython 3.15 free-threading Windows x86-64
SHA-256 checksum
How to use checksums
20bc5d654e16da62d7251d38456a8f349daeddc1b1946cc61b0d37154ddd937c
BLAKE2b-256 checksum
How to use checksums
55b38ec74b32e8c36b74845be04938c981ff022a7dc62544df74ad615bf91114
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / sway_orm-1.1.0-cp315-cp315t-musllinux_1_2_x86_64.whl

Download URL sway_orm-1.1.0-cp315-cp315t-musllinux_1_2_x86_64.whl
Size 3.2 MB
Tags CPython 3.15 CPython 3.15 free-threading Linux musl 1.2+ x86-64
SHA-256 checksum
How to use checksums
51f0f330cfb3da557c4f168c7c7fb5a164c3aaeaa81745faddc926fae188b6ca
BLAKE2b-256 checksum
How to use checksums
6a96b5997d01dc927035a33b617703143f4fbf8cf0555e3361b2c5e15a11e053
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / sway_orm-1.1.0-cp315-cp315t-musllinux_1_2_aarch64.whl

Download URL sway_orm-1.1.0-cp315-cp315t-musllinux_1_2_aarch64.whl
Size 3.1 MB
Tags CPython 3.15 CPython 3.15 free-threading Linux musl 1.2+ ARM64
SHA-256 checksum
How to use checksums
991d8dc10e9dbeb8f41fc63b64a15aa174ca5c471ffb27e92339cc9cc9943e7a
BLAKE2b-256 checksum
How to use checksums
c9bf05ec00aa8c758698435fe65656db42e8658269acc0eba9596343a107b409
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / sway_orm-1.1.0-cp315-cp315t-manylinux_2_28_x86_64.whl

Download URL sway_orm-1.1.0-cp315-cp315t-manylinux_2_28_x86_64.whl
Size 3.1 MB
Tags CPython 3.15 CPython 3.15 free-threading Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
751355ce65d4fe1a3d0d1d769f1a5dbf85a54d152f519dc46c71e973b9bf31d6
BLAKE2b-256 checksum
How to use checksums
560b82e1068991376c20079b21136237d58668a0c9fad22650e0471dc475d11b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / sway_orm-1.1.0-cp315-cp315t-manylinux_2_28_aarch64.whl

Download URL sway_orm-1.1.0-cp315-cp315t-manylinux_2_28_aarch64.whl
Size 2.9 MB
Tags CPython 3.15 CPython 3.15 free-threading Linux glibc 2.28+ ARM64
SHA-256 checksum
How to use checksums
73a36c04475c42074ad9d2f498dbcc79b692e82c6c85153e84da6788c7688985
BLAKE2b-256 checksum
How to use checksums
4253c86f3fd75f5ec975f74e5dcd8145a2492b76814b395d7581c24051903026
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / sway_orm-1.1.0-cp315-cp315t-macosx_11_0_arm64.whl

Download URL sway_orm-1.1.0-cp315-cp315t-macosx_11_0_arm64.whl
Size 2.0 MB
Tags CPython 3.15 CPython 3.15 free-threading macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
bcff4a35a3908249329d780a246664906cb651d52ca2f03a12947133fb649a67
BLAKE2b-256 checksum
How to use checksums
a6bb603b0c451750adf0f9d46504b08ebc321adf50b5ac0522d53bdcc55c9790
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / sway_orm-1.1.0-cp315-cp315-win_amd64.whl

Download URL sway_orm-1.1.0-cp315-cp315-win_amd64.whl
Size 2.0 MB
Tags CPython 3.15 Windows x86-64
SHA-256 checksum
How to use checksums
6beef62e010ebfab7173502ee8658f0c7a52a2c05c8fdb4e97189e4cd6257724
BLAKE2b-256 checksum
How to use checksums
51e18e1055ce6a7661e8a33d56fb0f0c99fd29be6855128040b720e1496d4cfa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / sway_orm-1.1.0-cp315-cp315-musllinux_1_2_x86_64.whl

Download URL sway_orm-1.1.0-cp315-cp315-musllinux_1_2_x86_64.whl
Size 3.2 MB
Tags CPython 3.15 Linux musl 1.2+ x86-64
SHA-256 checksum
How to use checksums
2859f42249d34dc1523f7c5700760ce075678e25f7ea63f8621e3e5503f35c03
BLAKE2b-256 checksum
How to use checksums
728c130eb68da254c8b76c603ad5486a128121ce51cf08d82ac2ce6430543cf7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / sway_orm-1.1.0-cp315-cp315-musllinux_1_2_aarch64.whl

Download URL sway_orm-1.1.0-cp315-cp315-musllinux_1_2_aarch64.whl
Size 3.1 MB
Tags CPython 3.15 Linux musl 1.2+ ARM64
SHA-256 checksum
How to use checksums
ea3f104631649facb0cfad895cc9d74d1c56887b24c39c8c978c41be07bb05e8
BLAKE2b-256 checksum
How to use checksums
ae5de2721b363f2b7f684df691cd90839d2a2e0865fd45a91afbf212332baf75
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / sway_orm-1.1.0-cp315-cp315-manylinux_2_28_x86_64.whl

Download URL sway_orm-1.1.0-cp315-cp315-manylinux_2_28_x86_64.whl
Size 3.1 MB
Tags CPython 3.15 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
380a860d1205745fa58987c68c03cab3b26cb7997f75a99559c1ad65dfd42906
BLAKE2b-256 checksum
How to use checksums
ca1dd7525e2886065f34e7f05c882f6477d484b64e668ae61a0c0842a31f29f5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / sway_orm-1.1.0-cp315-cp315-manylinux_2_28_aarch64.whl

Download URL sway_orm-1.1.0-cp315-cp315-manylinux_2_28_aarch64.whl
Size 2.9 MB
Tags CPython 3.15 Linux glibc 2.28+ ARM64
SHA-256 checksum
How to use checksums
6b167120dc62072618a1cc3794fb6d3f3aa18788b1198c46d85b30c8bb91be5d
BLAKE2b-256 checksum
How to use checksums
72abd3c22dffe3b4d2d533707724ac5e5d0c5410ac945feec64a74b3b2c428d4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / sway_orm-1.1.0-cp315-cp315-macosx_11_0_arm64.whl

Download URL sway_orm-1.1.0-cp315-cp315-macosx_11_0_arm64.whl
Size 2.0 MB
Tags CPython 3.15 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
69d3fc096aa2984f9184ea145c8f9a84d6d12f9edf3eaacc1591e24cbedae987
BLAKE2b-256 checksum
How to use checksums
e604e08e95cc1df9a06008a4f5a1515c287ca81921713c3bcfd2c0c4ea8fcd76
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for sway-orm 1.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.1.0 This release

13 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page