Skip to main content

DefPixel

Define your data connections, models, and access in Python.

Define your pixels.
Shape your voxels.

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 connections: storage-specific configuration and data access capabilities.
  • Define models: storage specifications and validation rules attached to standard dataclasses.
  • Use 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.

Sqlite

The Sqlite implementation is included in the base installation and uses Python's standard-library sqlite3. Model-based usage requires Sqlite 3.35+ as used by Python.

pip install DefPixel

PostgreSQL

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

pip install "DefPixel[PostgreSQL]"

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 0.1.3

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 0.1.3
File Size Uploaded Provenance Actions
defpixel-0.1.3.tar.gz 410.2 kB Without provenance Details for defpixel-0.1.3.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for DefPixel 0.1.3
File Interpreter ABI Platform Actions
defpixel-0.1.3-74-py3-none-any.whl Python 3 none any Details for defpixel-0.1.3-74-py3-none-any.whl
defpixel-0.1.3-73-py3-none-any.whl Python 3 none any Details for defpixel-0.1.3-73-py3-none-any.whl
defpixel-0.1.3-71-py3-none-any.whl Python 3 none any Details for defpixel-0.1.3-71-py3-none-any.whl

Total release size: 766.5 kB

Release files / defpixel-0.1.3.tar.gz

Download URL defpixel-0.1.3.tar.gz
Size 410.2 kB
Tags Source
SHA-256 checksum
How to use checksums
035bf54ce3196f7bc96f5daeab932a226f6a303822a38e6b4e2176e63200d36b
BLAKE2b-256 checksum
How to use checksums
a4e22ff18f33a612d5de6f1a08d834e8e49b95b0a6e26551b81d13e8fcacc69a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.17

Release files / defpixel-0.1.3-74-py3-none-any.whl

Download URL defpixel-0.1.3-74-py3-none-any.whl
Size 118.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e8ba6ac08b853c88c4a8e03c463ca334e12690246243545d968b6c22211d4269
BLAKE2b-256 checksum
How to use checksums
e3a881f07c18a17f213dc7bb2ab5b5c5c7c36ff4fb9d3e2d7a723474de2edd20
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.17

Release files / defpixel-0.1.3-73-py3-none-any.whl

Download URL defpixel-0.1.3-73-py3-none-any.whl
Size 118.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b358ca1743ca31249bf26d940c649766d1f03cce1d144e73b3c628d65ea2d01b
BLAKE2b-256 checksum
How to use checksums
74195176fba32199926d860147d23f0dc68f3dbeeb0830a74b13f9920c96e353
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.17

Release files / defpixel-0.1.3-71-py3-none-any.whl

Download URL defpixel-0.1.3-71-py3-none-any.whl
Size 118.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d0f8e0dda9482302ebd632b28cbf26056331cd48e9950263d9ec509d40fa1237
BLAKE2b-256 checksum
How to use checksums
611259e1fe669fd840b9731cd45eab062d86a1d856201005678884b6e942ac05
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.17

Security for DefPixel 0.1.3

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.

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