Skip to main content

DefPixel

Define your pixels. Design your voxels.
Define your connections, Design your models, and Dive into your data in Python.

DefPixel is a Python library for defining data source connections, models, and access. Use a provided data access implementation or build your own, and work with data directly or through standard dataclasses.

Connect · model · use

  • Define your connections: storage-specific configuration and data access capabilities.
  • Design your models: storage specifications and validation rules attached to standard dataclasses.
  • Dive into your data: direct access without models, or storage and retrieval through models.

Configuration and Connection provide connection foundations. Database, KeyValue, Document, and Index Protocols describe capabilities. Modeling approaches and support vary by implementation. Validators also provide independent value validation and conversion.

Requirements and installation

Python 3.10+ is required. The base pip install DefPixel installs only the core, without implementation code.

Sqlite

Select the Sqlite implementation with the Sqlite extra. It uses Python's standard-library sqlite3. Model-based usage requires Sqlite 3.35+ as used by Python.

pip install "DefPixel[Sqlite]"

PostgreSQL

Install the PostgreSQL extra to include the implementation and PostgreSQL driver. A running PostgreSQL 15–18 server is required. This installation excludes Sqlite.

pip install "DefPixel[PostgreSQL]"

Use pip install "DefPixel[Sqlite,PostgreSQL]" for both implementations. Each extra selects a separate, same-version distribution; existing import paths are unchanged. Before migrating an older integrated installation, uninstall DefPixel and any implementation distributions, then reinstall with the required extras. Sqlite is no longer included in the base installation. Omitting an extra later does not remove an already installed implementation.

MariaDB development status

The current source provides MariaDB connections, direct SQL, sessions, native pools, dataclass mapping, types, DDL, model CRUD, SELECT-backed views, query composition, scalar/aggregate/date-time/JSON/spatial/vector functions and JSON_TABLE sources through the MariaDB implementation selection. VECTOR types/indexes and vector functions require 11.7+; MBRCoveredBy requires 12.0+; JSON_TABLE requires 10.6+. Insert returns the first RETURNING row; Update/Delete return None. Final integration and regression validation remain in progress; YEAR=0 support is deferred. No release containing this feature has been published. Source development uses python -m pip install -e . --config-settings EXTRAS=MariaDB; include other implementation names in EXTRAS to keep them selected.

Usage at a glance

Database

Sqlite

Execute SQL directly for dictionary results or map standard dataclasses to tables and retrieve objects. This complete example requires Sqlite 3.35+ as used by Python.

from dataclasses import dataclass
from DefPixel.DataAccessObject.Implements.Sqlite import (
  Configuration, Connection, column, table,
)
from DefPixel.DataAccessObject.Implements.Sqlite.Constraints import PrimaryKey
from DefPixel.DataAccessObject.Implements.Sqlite.Executors import Create, Insert, Select
from DefPixel.DataAccessObject.Implements.Sqlite.Types import Integer, Text


@table(name='users', constraints=(PrimaryKey('id'),))
@dataclass
class User:
  id: int = column(Integer())
  name: str = column(Text())


connection = Connection(Configuration(':memory:'))
connection.connect()
try:
  with connection.session() as session:
    session.run(Create(User))
    session.run(Insert(User).values(id=1, name='Alice'))

    rows = session.execute(
      'SELECT id, name FROM users WHERE id = ?', 1,
    ).rows()
    print(rows)

    users = session.run(Select(User), fetch=User)
    print(users)
finally:
  connection.close()

Output:

[{'id': 1, 'name': 'Alice'}]
[User(id=1, name='Alice')]

Sessions commit on normal completion and roll back on exceptions. Direct SQL does not require models. Models remain ordinary Python objects; attribute assignment does not automatically persist changes. No custom Model base class or Service/Repository/DTO structure is required.

PostgreSQL

PostgreSQL also supports direct SQL alongside dataclass mappings. Install the PostgreSQL extra above and adjust the connection settings for your server. Run this example in a development database: it creates and drops the defpixel_readme_users table.

from dataclasses import dataclass
from DefPixel.DataAccessObject.Implements.PostgreSQL import (
  Configuration, Connection, Create, Drop, Insert, PrimaryKey, Select, column, table,
)
from DefPixel.DataAccessObject.Implements.PostgreSQL.Types import Integer, Text


@table('defpixel_readme_users', constraints=PrimaryKey('defpixel_readme_users_pk', 'id'))
@dataclass
class User:
  id: int = column(Integer())
  name: str = column(Text())


connection = Connection(Configuration(
  host='127.0.0.1', port=5432, database='defpixel',
  username='defpixel', password='change-me-local-only',
))
connection.connect()
try:
  with connection.session() as session:
    session.run(Create(User))
    session.run(Insert(User).values(id=1, name='Alice'))

    rows = session.execute(
      'SELECT id, name FROM defpixel_readme_users WHERE id = %s', 1,
    ).rows()
    print(rows)

    users = session.run(Select(User), fetch=User)
    print(users)
    session.run(Drop(User))
finally:
  connection.close()

Output:

[{'id': 1, 'name': 'Alice'}]
[User(id=1, name='Alice')]

Direct SQL binds positional arguments with %s and keyword arguments with %(name)s. PostgreSQL constraints take a name as their first argument.

Supported implementations

  • Sqlite: direct SQL, dataclass mappings, CRUD, tables, views, constraints, indexes, joins, aggregates, and transactions. Sqlite modeling requires Sqlite 3.35+.
  • PostgreSQL: direct SQL, dataclass mappings, CRUD, schemas, sequences, tables, views, constraints, indexes, joins, aggregate/window/JSON functions, nested transactions, and connection pools. Requires PostgreSQL 15–18 and the PostgreSQL extra.

Build your own

Implement the capability Protocols for the store you need, without inheriting a provided implementation or adapting every store to SQL.

The source repository includes step-by-step implementation development guides and Sqlite and PostgreSQL user manuals.

Metadata

Release files for DefPixel-PostgreSQL 0.1.6

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

Source distribution (sdist)

Source distribution for DefPixel-PostgreSQL 0.1.6
File Size Uploaded Provenance Actions
defpixel_postgresql-0.1.6.tar.gz 719.3 kB Without provenance Details for defpixel_postgresql-0.1.6.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for DefPixel-PostgreSQL 0.1.6
File Interpreter ABI Platform Actions
defpixel_postgresql-0.1.6-93-py3-none-any.whl Python 3 none any Details for defpixel_postgresql-0.1.6-93-py3-none-any.whl
defpixel_postgresql-0.1.6-92-py3-none-any.whl Python 3 none any Details for defpixel_postgresql-0.1.6-92-py3-none-any.whl
defpixel_postgresql-0.1.6-91-py3-none-any.whl Python 3 none any Details for defpixel_postgresql-0.1.6-91-py3-none-any.whl

Total release size: 926.6 kB

Release files / defpixel_postgresql-0.1.6.tar.gz

Download URL defpixel_postgresql-0.1.6.tar.gz
Size 719.3 kB
Tags Source
SHA-256 checksum
How to use checksums
58ad2960caef5a18ba71b4f3ae2570a751bf3bc5584d06d9ead47115b3f01414
BLAKE2b-256 checksum
How to use checksums
e9a70141fc8271e2ea5b038fea6b93b566edbca8b1eae15c48b9ad1bba2ee4aa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.18

Release files / defpixel_postgresql-0.1.6-93-py3-none-any.whl

Download URL defpixel_postgresql-0.1.6-93-py3-none-any.whl
Size 69.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d82d9cac7674d2f3a37c080de564c39028f4d5062178ec1bc826df1d0a186e21
BLAKE2b-256 checksum
How to use checksums
f9e97d691284fae159dc6ac7474df7dc33a953a3b2d58129971c5217bcbe5553
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.18

Release files / defpixel_postgresql-0.1.6-92-py3-none-any.whl

Download URL defpixel_postgresql-0.1.6-92-py3-none-any.whl
Size 69.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6d04b790c5578e17b419ee4003a8a2297fe00b807d0a1d36cd2a8761580c831c
BLAKE2b-256 checksum
How to use checksums
6a6df066926ce241dc4a9a5f206764dea577adab75afaa60e2e2cd8c4b823d3e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.18

Release files / defpixel_postgresql-0.1.6-91-py3-none-any.whl

Download URL defpixel_postgresql-0.1.6-91-py3-none-any.whl
Size 69.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f3b0bdfe887bf7637cff6d91e8899356597de0d7d770260ce7ea70f72d2f4b34
BLAKE2b-256 checksum
How to use checksums
62a197cfba16fe59dc6bff7bf738317210480be90ab5351c5f74b5f7a320bc69
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.18

Security for DefPixel-PostgreSQL 0.1.6

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

0.1.6 This release

4 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