Skip to main content

``hypothesis`` strategies for generating ``SQLAlchemy`` objects.

Project description

hypothesis strategies for SQLAlchemy

In what follows

  • python is an alias for python3.5 or any later version (python3.6 and so on),
  • pypy is an alias for pypy3.5 or any later version (pypy3.6 and so on).


Install the latest pip & setuptools packages versions:

  • with CPython
    python -m pip install --upgrade pip setuptools
  • with PyPy
    pypy -m pip install --upgrade pip setuptools


Download and install the latest stable version from PyPI repository:

  • with CPython
    python -m pip install --upgrade hypothesis_sqlalchemy
  • with PyPy
    pypy -m pip install --upgrade hypothesis_sqlalchemy


Download the latest version from GitHub repository

git clone
cd hypothesis_sqlalchemy

Install dependencies:

  • with CPython
    python -m pip install --force-reinstall -r requirements.txt
  • with PyPy
    pypy -m pip install --force-reinstall -r requirements.txt


  • with CPython
    python install
  • with PyPy
    pypy install


Let's take a look at what can be generated and how.


We can write a strategy that produces tables

>>> from hypothesis_sqlalchemy import tabular
>>> from sqlalchemy.schema import MetaData
>>> tables = tabular.factory(metadata=MetaData(),
...                          min_size=3,
...                          max_size=10)
>>> table = tables.example()
>>> from sqlalchemy.schema import Table
>>> isinstance(table, Table)
>>> from sqlalchemy.schema import Column
>>> all(isinstance(column, Column) for column in table.columns)
>>> 3 <= len(table.columns) <= 10


Suppose we have a table

>>> from sqlalchemy.schema import (Column,
...                                MetaData,
...                                Table)
>>> from sqlalchemy.sql.sqltypes import (Integer,
...                                      String)
>>> metadata = MetaData()
>>> user_table = Table('user', metadata,
...                    Column('user_id', Integer,
...                           primary_key=True),
...                    Column('user_name', String(16),
...                           nullable=False),
...                    Column('email_address', String(60)),
...                    Column('password', String(20),
...                           nullable=False))

and we can write strategy that

  • produces single records (as tuples)
    >>> from hypothesis import strategies
    >>> from hypothesis_sqlalchemy import tabular
    >>> records = tabular.records.factory(user_table, 
    ...                                   email_address=strategies.emails())
    >>> record = records.example()
    >>> isinstance(record, tuple)
    >>> len(record) == len(user_table.columns)
    >>> all(column.nullable and value is None
    ...     or isinstance(value, column.type.python_type) 
    ...     for value, column in zip(record, user_table.columns))
  • produces records lists (with configurable list size bounds)
    >>> from hypothesis_sqlalchemy import tabular
    >>> records_lists = tabular.records.lists_factory(user_table,
    ...                                               min_size=2,
    ...                                               max_size=5, 
    ...                                               email_address=strategies.emails())
    >>> records_list = records_lists.example()
    >>> isinstance(records_list, list)
    >>> 2 <= len(records_list) <= 5
    >>> all(isinstance(record, tuple) for record in records_list)
    >>> all(len(record) == len(user_table.columns) for record in records_list)


Bumping version


Install bump2version.


Choose which version number category to bump following semver specification.

Test bumping version

bump2version --dry-run --verbose $CATEGORY

where $CATEGORY is the target version number category name, possible values are patch/minor/major.

Bump version

bump2version --verbose $CATEGORY

This will set version to major.minor.patch-alpha.


Test bumping version

bump2version --dry-run --verbose release

Bump version

bump2version --verbose release

This will set version to major.minor.patch.

Running tests

Install dependencies:

  • with CPython
    python -m pip install --force-reinstall -r requirements-tests.txt
  • with PyPy
    pypy -m pip install --force-reinstall -r requirements-tests.txt



Inside Docker container:

  • with CPython
    docker-compose --file docker-compose.cpython.yml up
  • with PyPy
    docker-compose --file docker-compose.pypy.yml up

Bash script (e.g. can be used in Git hooks):

  • with CPython



    ./ cpython
  • with PyPy

    ./ pypy

PowerShell script (e.g. can be used in Git hooks):

  • with CPython
    .\run-tests.ps1 cpython
  • with PyPy
    .\run-tests.ps1 pypy

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for hypothesis-sqlalchemy, version 0.3.2
Filename, size File type Python version Upload date Hashes
Filename, size hypothesis_sqlalchemy-0.3.2-py3-none-any.whl (13.5 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size hypothesis_sqlalchemy-0.3.2.tar.gz (8.8 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page