title: sqlalchemy.dialects.postgresql BIT Example Code category: page slug: sqlalchemy-dialects-postgresql-bit-examples sortorder: 500031009 toc: False sidebartitle: sqlalchemy.dialects.postgresql BIT meta: Python example code that shows how to use the BIT constant from the sqlalchemy.dialects.postgresql module of the SQLAlchemy project.
BIT is a constant within the sqlalchemy.dialects.postgresql module of the SQLAlchemy project.
ARRAY,
BIGINT,
DOUBLE_PRECISION,
ExcludeConstraint,
INTEGER,
JSON,
TSVECTOR,
array,
json,
and pypostgresql
are several other callables with code examples from the same sqlalchemy.dialects.postgresql package.
sqlalchemy-utils (project documentation and PyPI package information) is a code library with various helper functions and new data types that make it easier to use SQLAlchemy when building projects that involve more specific storage requirements such as currency. The wide array of data types includes ranged values and aggregated attributes.
sqlalchemy-utils / sqlalchemy_utils / types / bit.py
# bit.py
import sqlalchemy as sa
~~from sqlalchemy.dialects.postgresql import BIT
class BitType(sa.types.TypeDecorator):
impl = sa.types.BINARY
def __init__(self, length=1, **kwargs):
self.length = length
sa.types.TypeDecorator.__init__(self, **kwargs)
def load_dialect_impl(self, dialect):
if dialect.name == 'postgresql':
return dialect.type_descriptor(BIT(self.length))
elif dialect.name == 'sqlite':
return dialect.type_descriptor(sa.String(self.length))
else:
return dialect.type_descriptor(type(self.impl)(self.length))
## ... source file continues with no further BIT examples...