Skip to main content

View Manipulation for SQLAlchemy

Adds CreateView and DropView constructs to SQLAlchemy.

Status

Current version is 0.3.2; releases are infrequent as the code here is small and based on stable pieces of the SQLAlchemy API, so there has been minimal maintenance required so far to keep compatibility with new SQLAlchemy or python versions.

This package is working with latest Python and SQLAlchemy (1.0+ and 2.0) as of early 2023.

Usage

Examples:

>>> from sqlalchemy import Table, MetaData
>>> from sqlalchemy.sql import text
>>> from sqlalchemy_views import CreateView, DropView
>>> view = Table('my_view', MetaData())
>>> definition = text("SELECT * FROM my_table")
>>> create_view = CreateView(view, definition)
>>> print(str(create_view.compile()).strip())
CREATE VIEW my_view AS SELECT * FROM my_table
>>> create_view = CreateView(view, definition, or_replace=True)
>>> print(str(create_view.compile()).strip())
CREATE OR REPLACE VIEW my_view AS SELECT * FROM my_table
>>> create_view = CreateView(view, definition, options={'check_option': 'local'})
>>> print(str(create_view.compile()).strip())
CREATE VIEW my_view WITH (check_option=local) AS SELECT * FROM my_table
>>> drop_view = DropView(view)
>>> print(str(drop_view.compile()).strip())
DROP VIEW my_view
>>> drop_view = DropView(view, if_exists=True, cascade=True)
>>> print(str(drop_view.compile()).strip())
DROP VIEW IF EXISTS my_view CASCADE

Note that the SQLAlchemy Table object is used to represent both tables and views. To introspect a view, create a Table with autoload=True, and then use SQLAlchemy’s get_view_definition method to generate the second argument to CreateView.

Installation

sqlalchemy-views is available on PyPI and can be installed via pip

pip install sqlalchemy-views

Limitations

Various SQL dialects have developed custom CREATE VIEW and DROP VIEW syntax. This project aims to provide the core set of functionality shared by most database engines.

Acknowledgements

Some design ideas taken from the SQLAlchemy Usage Recipe for views.

Package structure is based on python-project-template.

And thank you to the various contributors!

Release files for sqlalchemy-views 0.3.2

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

Source distribution (sdist)

Source distribution for sqlalchemy-views 0.3.2
File Size Uploaded
sqlalchemy-views-0.3.2.tar.gz 18.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sqlalchemy-views 0.3.2
File Interpreter ABI Platform
sqlalchemy_views-0.3.2-py3-none-any.whl Python 3 none any Details

Total release size: 24.6 kB

Release files / sqlalchemy-views-0.3.2.tar.gz

Download URL sqlalchemy-views-0.3.2.tar.gz
Size 18.9 kB
Tags Source
SHA-256 checksum
How to use checksums
c396416939bc4459c71f15c0279b72c9eb1f92fe022afe7fa74ed3adeef76e3b
BLAKE2b-256 checksum
How to use checksums
cb9b08dbe2c33ccc2e901fd31de1e2fec79df0ba788e1d08c688f18ac1c00e5d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.4

Release files / sqlalchemy_views-0.3.2-py3-none-any.whl

Download URL sqlalchemy_views-0.3.2-py3-none-any.whl
Size 5.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
53a376efc8badbbd6d2d360f0d03fc70f1f5ee7748cf169506ea8a6e4f20326c
BLAKE2b-256 checksum
How to use checksums
afab2802a1a5b4a3c5d6ef28c680cafbdca6345639778be56ce8a0862ea0d164
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.4

Release history Release notifications | RSS feed

This release

0.3.2 This release

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

1 release file

0.2.1

1 release file

0.2

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