Example App Reference

Models

chinook_api.models

SQLAlchemy models for the Chinook database.

class examples.chinook_api.models.Album(**kwargs)[source]

SQLAlchemy model for the Album table in our database.

album_id
title
artist_id
artist
__init__(**kwargs)

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

class examples.chinook_api.models.Artist(**kwargs)[source]

SQLAlchemy model for the Artist table in our database.

artist_id
name
__init__(**kwargs)

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

class examples.chinook_api.models.Customer(**kwargs)[source]

SQLAlchemy model for the Customer table in our database.

customer_id
first_name
last_name
company
address
city
state

Two Character Abbreviation

country
postal_code
phone
fax
email
support_rep_id
employee
__init__(**kwargs)

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

class examples.chinook_api.models.Employee(**kwargs)[source]

SQLAlchemy model for the Employee table in our database.

employee_id
last_name
first_name
title
reports_to
birth_date
hire_date
address
city
state
country
postal_code
phone
fax
email
manager
__init__(**kwargs)

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

class examples.chinook_api.models.Genre(**kwargs)[source]

SQLAlchemy model for the Genre table in our database.

genre_id
name
__init__(**kwargs)

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

class examples.chinook_api.models.Invoice(**kwargs)[source]

SQLAlchemy model for the Invoice table in our database.

invoice_id
customer_id
invoice_date
billing_address
billing_city
billing_state
billing_country
billing_postal_code
total
customer
__init__(**kwargs)

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

class examples.chinook_api.models.InvoiceLine(**kwargs)[source]

SQLAlchemy model for the InvoiceLine table in our database.

invoice_line_id
invoice_id
track_id
unit_price
quantity
invoice
track
__init__(**kwargs)

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

class examples.chinook_api.models.MediaType(**kwargs)[source]

SQLAlchemy model for the MediaType table in our database.

media_type_id
name
__init__(**kwargs)

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

class examples.chinook_api.models.Playlist(**kwargs)[source]

SQLAlchemy model for the Playlist table in our database.

playlist_id
name
tracks
__init__(**kwargs)

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

class examples.chinook_api.models.Track(**kwargs)[source]

SQLAlchemy model for the Track table in our database.

track_id
name
album_id
media_type_id
genre_id
composer
milliseconds
bytes
unit_price
album
genre
media_type
__init__(**kwargs)

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

class examples.chinook_api.models.Node(**kwargs)[source]

SQLAlchemy model for the Node table in our database.

node_id
children
__init__(**kwargs)

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

class examples.chinook_api.models.CompositeNode(**kwargs)[source]

SQLAlchemy model for the CompositeNode table in our database.

node_id
composite_id
children
__init__(**kwargs)

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

class examples.chinook_api.models.CompositeOne(**kwargs)[source]

Dummy model for one side of one to many composite key testing.

one_id
composite_one_id
__init__(**kwargs)

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

class examples.chinook_api.models.CompositeMany(**kwargs)[source]

Model for many side of one to many composite key testing.

many_id
one_id
composite_one_id
one
__init__(**kwargs)

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

Schemas

chinook_api.schemas

Drowsy Schemas for the Chinook database.

class examples.chinook_api.schemas.AlbumSchema(only=None, exclude=(), many=False, context=None, load_only=(), dump_only=(), partial=False, unknown=None, instance=None, parent_resource=None, session=None)[source]
class Meta[source]
model

alias of Album

include_relationships = True
opts: Any = <drowsy.schema.ModelResourceSchemaOpts object>
exclude: set[Any] | MutableSet[Any]
unknown: types.UnknownOption
fields: dict[str, Field]

Dictionary mapping field_names -> Field objects

load_fields: dict[str, Field]
dump_fields: dict[str, Field]
instance: _ModelType | None
class examples.chinook_api.schemas.ArtistSchema(only=None, exclude=(), many=False, context=None, load_only=(), dump_only=(), partial=False, unknown=None, instance=None, parent_resource=None, session=None)[source]
class Meta[source]
model

alias of Artist

include_relationships = True
opts: Any = <drowsy.schema.ModelResourceSchemaOpts object>
exclude: set[Any] | MutableSet[Any]
unknown: types.UnknownOption
fields: dict[str, Field]

Dictionary mapping field_names -> Field objects

load_fields: dict[str, Field]
dump_fields: dict[str, Field]
instance: _ModelType | None
class examples.chinook_api.schemas.InvoiceLineSchema(only=None, exclude=(), many=False, context=None, load_only=(), dump_only=(), partial=False, unknown=None, instance=None, parent_resource=None, session=None)[source]
class Meta[source]
model

alias of InvoiceLine

include_relationships = True
opts: Any = <drowsy.schema.ModelResourceSchemaOpts object>
exclude: set[Any] | MutableSet[Any]
unknown: types.UnknownOption
fields: dict[str, Field]

Dictionary mapping field_names -> Field objects

load_fields: dict[str, Field]
dump_fields: dict[str, Field]
instance: _ModelType | None
class examples.chinook_api.schemas.InvoiceSchema(only=None, exclude=(), many=False, context=None, load_only=(), dump_only=(), partial=False, unknown=None, instance=None, parent_resource=None, session=None)[source]
class Meta[source]
model

alias of Invoice

include_relationships = True
opts: Any = <drowsy.schema.ModelResourceSchemaOpts object>
exclude: set[Any] | MutableSet[Any]
unknown: types.UnknownOption
fields: dict[str, Field]

Dictionary mapping field_names -> Field objects

load_fields: dict[str, Field]
dump_fields: dict[str, Field]
instance: _ModelType | None
class examples.chinook_api.schemas.EmployeeSchema(only=None, exclude=(), many=False, context=None, load_only=(), dump_only=(), partial=False, unknown=None, instance=None, parent_resource=None, session=None)[source]
class Meta[source]
model

alias of Employee

include_relationships = True
opts: Any = <drowsy.schema.ModelResourceSchemaOpts object>
exclude: set[Any] | MutableSet[Any]
unknown: types.UnknownOption
fields: dict[str, Field]

Dictionary mapping field_names -> Field objects

load_fields: dict[str, Field]
dump_fields: dict[str, Field]
instance: _ModelType | None
class examples.chinook_api.schemas.CustomerSchema(only=None, exclude=(), many=False, context=None, load_only=(), dump_only=(), partial=False, unknown=None, instance=None, parent_resource=None, session=None)[source]
class Meta[source]
model

alias of Customer

include_relationships = True
opts: Any = <drowsy.schema.ModelResourceSchemaOpts object>
exclude: set[Any] | MutableSet[Any]
unknown: types.UnknownOption
fields: dict[str, Field]

Dictionary mapping field_names -> Field objects

load_fields: dict[str, Field]
dump_fields: dict[str, Field]
instance: _ModelType | None
class examples.chinook_api.schemas.PlaylistSchema(only=None, exclude=(), many=False, context=None, load_only=(), dump_only=(), partial=False, unknown=None, instance=None, parent_resource=None, session=None)[source]
class Meta[source]
model

alias of Playlist

include_relationships = True
opts: Any = <drowsy.schema.ModelResourceSchemaOpts object>
exclude: set[Any] | MutableSet[Any]
unknown: types.UnknownOption
fields: dict[str, Field]

Dictionary mapping field_names -> Field objects

load_fields: dict[str, Field]
dump_fields: dict[str, Field]
instance: _ModelType | None
class examples.chinook_api.schemas.MediaTypeSchema(only=None, exclude=(), many=False, context=None, load_only=(), dump_only=(), partial=False, unknown=None, instance=None, parent_resource=None, session=None)[source]
class Meta[source]
model

alias of MediaType

include_relationships = True
opts: Any = <drowsy.schema.ModelResourceSchemaOpts object>
exclude: set[Any] | MutableSet[Any]
unknown: types.UnknownOption
fields: dict[str, Field]

Dictionary mapping field_names -> Field objects

load_fields: dict[str, Field]
dump_fields: dict[str, Field]
instance: _ModelType | None
class examples.chinook_api.schemas.GenreSchema(only=None, exclude=(), many=False, context=None, load_only=(), dump_only=(), partial=False, unknown=None, instance=None, parent_resource=None, session=None)[source]
class Meta[source]
model

alias of Genre

include_relationships = True
opts: Any = <drowsy.schema.ModelResourceSchemaOpts object>
exclude: set[Any] | MutableSet[Any]
unknown: types.UnknownOption
fields: dict[str, Field]

Dictionary mapping field_names -> Field objects

load_fields: dict[str, Field]
dump_fields: dict[str, Field]
instance: _ModelType | None
class examples.chinook_api.schemas.TrackSchema(only=None, exclude=(), many=False, context=None, load_only=(), dump_only=(), partial=False, unknown=None, instance=None, parent_resource=None, session=None)[source]
class Meta[source]
model

alias of Track

include_relationships = True
opts: Any = <drowsy.schema.ModelResourceSchemaOpts object>
exclude: set[Any] | MutableSet[Any]
unknown: types.UnknownOption
fields: dict[str, Field]

Dictionary mapping field_names -> Field objects

load_fields: dict[str, Field]
dump_fields: dict[str, Field]
instance: _ModelType | None
class examples.chinook_api.schemas.TrackPermissionsSchema(only=None, exclude=(), many=False, context=None, load_only=(), dump_only=(), partial=False, unknown=None, instance=None, parent_resource=None, session=None)[source]
class Meta[source]
model

alias of Track

include_relationships = True
opts: Any = <drowsy.schema.ModelResourceSchemaOpts object>
exclude: set[Any] | MutableSet[Any]
unknown: types.UnknownOption
fields: dict[str, Field]

Dictionary mapping field_names -> Field objects

load_fields: dict[str, Field]
dump_fields: dict[str, Field]
instance: _ModelType | None
class examples.chinook_api.schemas.NodeSchema(only=None, exclude=(), many=False, context=None, load_only=(), dump_only=(), partial=False, unknown=None, instance=None, parent_resource=None, session=None)[source]
class Meta[source]
model

alias of Node

include_relationships = True
opts: Any = <drowsy.schema.ModelResourceSchemaOpts object>
exclude: set[Any] | MutableSet[Any]
unknown: types.UnknownOption
fields: dict[str, Field]

Dictionary mapping field_names -> Field objects

load_fields: dict[str, Field]
dump_fields: dict[str, Field]
instance: _ModelType | None
class examples.chinook_api.schemas.CompositeNodeSchema(only=None, exclude=(), many=False, context=None, load_only=(), dump_only=(), partial=False, unknown=None, instance=None, parent_resource=None, session=None)[source]
class Meta[source]
model

alias of CompositeNode

include_relationships = True
opts: Any = <drowsy.schema.ModelResourceSchemaOpts object>
exclude: set[Any] | MutableSet[Any]
unknown: types.UnknownOption
fields: dict[str, Field]

Dictionary mapping field_names -> Field objects

load_fields: dict[str, Field]
dump_fields: dict[str, Field]
instance: _ModelType | None
class examples.chinook_api.schemas.CompositeOneSchema(only=None, exclude=(), many=False, context=None, load_only=(), dump_only=(), partial=False, unknown=None, instance=None, parent_resource=None, session=None)[source]
class Meta[source]
model

alias of CompositeOne

include_relationships = True
opts: Any = <drowsy.schema.ModelResourceSchemaOpts object>
exclude: set[Any] | MutableSet[Any]
unknown: types.UnknownOption
fields: dict[str, Field]

Dictionary mapping field_names -> Field objects

load_fields: dict[str, Field]
dump_fields: dict[str, Field]
instance: _ModelType | None
class examples.chinook_api.schemas.CompositeManySchema(only=None, exclude=(), many=False, context=None, load_only=(), dump_only=(), partial=False, unknown=None, instance=None, parent_resource=None, session=None)[source]
class Meta[source]
model

alias of CompositeMany

include_relationships = True
opts: Any = <drowsy.schema.ModelResourceSchemaOpts object>
exclude: set[Any] | MutableSet[Any]
unknown: types.UnknownOption
fields: dict[str, Field]

Dictionary mapping field_names -> Field objects

load_fields: dict[str, Field]
dump_fields: dict[str, Field]
instance: _ModelType | None

Resources

chinook_api.resources

Resources used for Chinook API purposes.

class examples.chinook_api.resources.AlbumResource(session, context=None, page_max_size=None, error_messages=None, parent_field=None)[source]
class Meta[source]
schema_cls

alias of AlbumSchema

opts = <drowsy.resource.ResourceOpts object>
class examples.chinook_api.resources.InvoiceLineResource(session, context=None, page_max_size=None, error_messages=None, parent_field=None)[source]
class Meta[source]
schema_cls

alias of InvoiceLineSchema

opts = <drowsy.resource.ResourceOpts object>
class examples.chinook_api.resources.InvoiceResource(session, context=None, page_max_size=None, error_messages=None, parent_field=None)[source]
class Meta[source]
schema_cls

alias of InvoiceSchema

opts = <drowsy.resource.ResourceOpts object>
class examples.chinook_api.resources.EmployeeResource(session, context=None, page_max_size=None, error_messages=None, parent_field=None)[source]
class Meta[source]
schema_cls

alias of EmployeeSchema

opts = <drowsy.resource.ResourceOpts object>
class examples.chinook_api.resources.CustomerResource(session, context=None, page_max_size=None, error_messages=None, parent_field=None)[source]
class Meta[source]
schema_cls

alias of CustomerSchema

opts = <drowsy.resource.ResourceOpts object>
class examples.chinook_api.resources.PlaylistResource(session, context=None, page_max_size=None, error_messages=None, parent_field=None)[source]
class Meta[source]
schema_cls

alias of PlaylistSchema

opts = <drowsy.resource.ResourceOpts object>
class examples.chinook_api.resources.MediaTypeResource(session, context=None, page_max_size=None, error_messages=None, parent_field=None)[source]
class Meta[source]
schema_cls

alias of MediaTypeSchema

opts = <drowsy.resource.ResourceOpts object>
class examples.chinook_api.resources.GenreResource(session, context=None, page_max_size=None, error_messages=None, parent_field=None)[source]
class Meta[source]
schema_cls

alias of GenreSchema

opts = <drowsy.resource.ResourceOpts object>
class examples.chinook_api.resources.TrackResource(session, context=None, page_max_size=None, error_messages=None, parent_field=None)[source]
class Meta[source]
schema_cls

alias of TrackSchema

opts = <drowsy.resource.ResourceOpts object>
class examples.chinook_api.resources.ArtistResource(session, context=None, page_max_size=None, error_messages=None, parent_field=None)[source]
class Meta[source]
schema_cls

alias of ArtistSchema

opts = <drowsy.resource.ResourceOpts object>
class examples.chinook_api.resources.NodeResource(session, context=None, page_max_size=None, error_messages=None, parent_field=None)[source]
class Meta[source]
schema_cls

alias of NodeSchema

opts = <drowsy.resource.ResourceOpts object>
class examples.chinook_api.resources.CompositeNodeResource(session, context=None, page_max_size=None, error_messages=None, parent_field=None)[source]
class Meta[source]
schema_cls

alias of CompositeNodeSchema

opts = <drowsy.resource.ResourceOpts object>
class examples.chinook_api.resources.CompositeOneResource(session, context=None, page_max_size=None, error_messages=None, parent_field=None)[source]
class Meta[source]
schema_cls

alias of CompositeOneSchema

opts = <drowsy.resource.ResourceOpts object>
class examples.chinook_api.resources.CompositeManyResource(session, context=None, page_max_size=None, error_messages=None, parent_field=None)[source]
class Meta[source]
schema_cls

alias of CompositeManySchema

opts = <drowsy.resource.ResourceOpts object>

API App

chinook_api.api

Simple implementation of a Flask API using Drowsy.

examples.chinook_api.api.prepare_db_session()[source]

Prepare a database session and attach it to Flask.g

examples.chinook_api.api.end_db_session(error)[source]

Commit any changes or rollback on failure.

examples.chinook_api.api.url_for_other_page(page)[source]

Simple helper function for pagination headers.

examples.chinook_api.api.swagger_spec_router()[source]

Serve up our swagger spec.

examples.chinook_api.api.api_router(path)[source]

Generic API router.

You’ll probably want to be more specific with your routing.

We’re using the ModelResourceRouter, which automatically routes based on the class name of each Resource, and handles nested routing, querying, and updating automatically.