Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Type Conversion

Python -> MySQL

Python TypeMySQL Binary Protocol Encoding
NoneNULL
boolInt64
intInt64
floatDouble(Float64)
str | bytes | bytearrayBytes
tuple | list | set | frozenset | dictjson-encoded string as Bytes
datetime.datetimeDate(year, month, day, hour, minute, second, microsecond)
datetime.dateDate(year, month, day, 0, 0, 0, 0)
datetime.timeTime(false, 0, hour, minute, second, microsecond)
datetime.timedeltaTime(is_negative, days, hours, minutes, seconds, microseconds)
time.struct_timeDate(year, month, day, hour, minute, second, 0)
decimal.DecimalBytes(str(Decimal))
uuid.UUIDBytes(UUID.hex)

MySQL -> Python

MySQL ColumnPython
NULLNone
INT / TINYINT / SMALLINT / MEDIUMINT / BIGINT / YEARint
FLOAT / DOUBLEfloat
DECIMAL / NUMERICdecimal.Decimal
DATEdatetime.date or None (0000-00-00)
DATETIME / TIMESTAMPdatetime.datetime or None (0000-00-00 00:00:00)
TIMEdatetime.timedelta
CHAR / VARCHAR / TEXT / TINYTEXT / MEDIUMTEXT / LONGTEXTstr
BINARY / VARBINARY / BLOB / TINYBLOB / MEDIUMBLOB / LONGBLOBbytes
JSONstr or the result of json.loads()
ENUM / SETstr
BITbytes
GEOMETRYbytes