pytds – main module

pytds.login – various login mechanisms, e.g. NTLM, Negotiate, SSPI

pytds.tds_base – Internal classes

class pytds.tds_base.AuthProtocol(*args, **kwargs)[source]
exception pytds.tds_base.ClosedConnectionError[source]

This error is raised when MSSQL server closes connection.

class pytds.tds_base.Column(name='', type=None, flags=1, value=None)[source]

Describes table column. Can be used to define schema for bulk insert.

Following flags can be used for columns in flags parameter:

  • fNullable - column can contain NULL values

  • fCaseSen - column is case-sensitive

  • fReadWrite - TODO document

  • fIdentity - TODO document

  • fComputed - TODO document

Parameters:
  • name (str) – Name of the column

  • type – Type of a column, e.g. pytds.tds_types.IntType

  • flags – Combination of flags for the column, multiple flags can be combined using binary or operator. Possible flags are described above.

choose_serializer(type_factory, collation)[source]

Chooses appropriate data type serializer for column’s data type.

class pytds.tds_base.DBAPITypeObject(*values)[source]

TODO add documentation

exception pytds.tds_base.DataError[source]

This error is raised when input parameter contains data which cannot be converted to acceptable data type.

exception pytds.tds_base.DatabaseError(msg: str, exc: Any | None = None)[source]

This error is raised when MSSQL server returns an error which includes error number

exception pytds.tds_base.Error[source]

Base class for all error classes, except TimeoutError

exception pytds.tds_base.IntegrityError(msg: str, exc: Any | None = None)[source]

TODO add documentation

exception pytds.tds_base.InterfaceError[source]

TODO add documentation

exception pytds.tds_base.InternalError(msg: str, exc: Any | None = None)[source]

TODO add documentation

class pytds.tds_base.InternalProc(proc_id, name)[source]

TODO add documentation

class pytds.tds_base.LoadBalancer(*args, **kwargs)[source]
exception pytds.tds_base.LoginError(msg: str, exc: Any | None = None)[source]

This error is raised if provided login credentials are invalid

class pytds.tds_base.Message[source]
exception pytds.tds_base.NotSupportedError(msg: str, exc: Any | None = None)[source]

TODO add documentation

exception pytds.tds_base.OperationalError(msg: str, exc: Any | None = None)[source]

TODO add documentation

class pytds.tds_base.Param(name: str = '', type=None, value=None, flags: int = 0)[source]

Describes typed parameter. Can be used to explicitly specify type of the parameter in the parametrized query.

Parameters:
class pytds.tds_base.PreLoginEnc[source]

PRELOGIN encryption parameter.

Spec link: https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-tds/60f56408-0188-4cd5-8b90-25c6f2423868

class pytds.tds_base.PreLoginToken[source]

PRELOGIN token option identifiers, corresponds to PL_OPTION_TOKEN in the spec.

Spec link: https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-tds/60f56408-0188-4cd5-8b90-25c6f2423868

exception pytds.tds_base.ProgrammingError(msg: str, exc: Any | None = None)[source]

TODO add documentation

class pytds.tds_base.Route[source]
class pytds.tds_base.TransportProtocol(*args, **kwargs)[source]

This protocol mimics socket protocol

exception pytds.tds_base.Warning[source]
pytds.tds_base.force_unicode(s)[source]

Convert input into a string. If input is a byte array, it will be decoded using UTF8 decoder.

pytds.tds_base.iterdecode(iterable, codec)[source]

Uses an incremental decoder to decode each chunk of string in iterable. This function is a generator.

Parameters:
  • iterable – Iterable object which yields raw data to be decoded.

  • codec – An instance of a codec which will be used for decoding.

pytds.tds_base.read_chunks(stm, size)[source]

Reads exactly size bytes from stm and produces chunks

May call stm.read multiple times until required number of bytes is read. If EOF is reached before size bytes are read will raise ClosedConnectionError

Parameters:
  • stm – Stream to read bytes from, should have read method, this read method can return less than requested number of bytes.

  • size – Number of bytes to read.

pytds.tds_base.readall(stm, size)[source]

Reads exactly size bytes from stm

May call stm.read multiple times until required number of bytes read. If EOF is reached before size bytes are read will raise ClosedConnectionError

Parameters:
  • stm – Stream to read bytes from, should have read method this read method can return less than requested number of bytes.

  • size – Number of bytes to read.

Returns:

Bytes buffer of exactly given size.

pytds.tds_base.readall_fast(stm, size)[source]

Slightly faster version of readall, it reads no more than two chunks. Meaning that it can only be used to read small data that doesn’t span more that two packets.

Parameters:
  • stm – Stream to read from, should have read method.

  • size – Number of bytes to read.

Returns:

pytds.tds_base.skipall(stm, size)[source]

Skips exactly size bytes in stm

If EOF is reached before size bytes are skipped will raise ClosedConnectionError

Parameters:
  • stm – Stream to skip bytes in, should have read method this read method can return less than requested number of bytes.

  • size – Number of bytes to skip.

pytds.tds_base.tds7_crypt_pass(password: str) bytearray[source]

Mangle password according to tds rules

Parameters:

password – Password str

Returns:

Byte-string with encoded password

pytds.tds_base.tds_quote_id(ident)[source]

Quote an identifier according to MSSQL rules

Parameters:

ident – identifier to quote

Returns:

Quoted identifier

pytds.tds_base.total_seconds(td)[source]

Total number of seconds in timedelta object

Python 2.6 doesn’t have total_seconds method, this function provides a backport

pytds.tds_types – Column type classes

This module implements various data types supported by Microsoft SQL Server

class pytds.tds_types.BaseDateTime73Serializer(precision=None, scale=None, size=None)[source]
classmethod from_stream(r)[source]

Class method that reads and returns a type instance.

Parameters:

r – An instance of _TdsReader to read type from.

Should be implemented in actual types.

read(r)[source]

Reads value from the stream.

Parameters:

r – An instance of _TdsReader to read value from.

Returns:

A read value.

Should be implemented in actual types.

write(w, value)[source]

Writes type’s value into stream

Parameters:
  • w – An instance of _TdsWriter to write into.

  • value – A value to be stored, should be compatible with the type

Should be implemented in actual types.

write_info(w)[source]

Writes type info into w stream.

Parameters:

w – An instance of _TdsWriter to write into.

Should be symmetrical to from_stream method. Should be implemented in actual types.

class pytds.tds_types.BaseDateTimeSerializer(precision=None, scale=None, size=None)[source]
classmethod from_stream(r)[source]

Class method that reads and returns a type instance.

Parameters:

r – An instance of _TdsReader to read type from.

Should be implemented in actual types.

read(r)[source]

Reads value from the stream.

Parameters:

r – An instance of _TdsReader to read value from.

Returns:

A read value.

Should be implemented in actual types.

write(w, value)[source]

Writes type’s value into stream

Parameters:
  • w – An instance of _TdsWriter to write into.

  • value – A value to be stored, should be compatible with the type

Should be implemented in actual types.

write_info(w)[source]

Writes type info into w stream.

Parameters:

w – An instance of _TdsWriter to write into.

Should be symmetrical to from_stream method. Should be implemented in actual types.

class pytds.tds_types.BasePrimitiveTypeSerializer(precision=None, scale=None, size=None)[source]

Base type for primitive TDS data types.

Primitive type is a fixed size type with no type arguments. All primitive TDS types should derive from it. In addition actual types should provide the following:

  • type - class variable storing type identifier

  • declaration - class variable storing name of sql type

  • isntance - class variable storing instance of class

classmethod from_stream(r)[source]

Class method that reads and returns a type instance.

Parameters:

r – An instance of _TdsReader to read type from.

Should be implemented in actual types.

read(r)[source]

Reads value from the stream.

Parameters:

r – An instance of _TdsReader to read value from.

Returns:

A read value.

Should be implemented in actual types.

write(w, value)[source]

Writes type’s value into stream

Parameters:
  • w – An instance of _TdsWriter to write into.

  • value – A value to be stored, should be compatible with the type

Should be implemented in actual types.

write_info(w)[source]

Writes type info into w stream.

Parameters:

w – An instance of _TdsWriter to write into.

Should be symmetrical to from_stream method. Should be implemented in actual types.

class pytds.tds_types.BaseTypeSerializer(precision=None, scale=None, size=None)[source]

Base type for TDS data types.

All TDS types should derive from it. In addition actual types should provide the following:

  • type - class variable storing type identifier

classmethod from_stream(r)[source]

Class method that reads and returns a type instance.

Parameters:

r – An instance of _TdsReader to read type from.

Should be implemented in actual types.

get_typeid()[source]

Returns type identifier of type.

read(r)[source]

Reads value from the stream.

Parameters:

r – An instance of _TdsReader to read value from.

Returns:

A read value.

Should be implemented in actual types.

write(w, value)[source]

Writes type’s value into stream

Parameters:
  • w – An instance of _TdsWriter to write into.

  • value – A value to be stored, should be compatible with the type

Should be implemented in actual types.

write_info(w)[source]

Writes type info into w stream.

Parameters:

w – An instance of _TdsWriter to write into.

Should be symmetrical to from_stream method. Should be implemented in actual types.

class pytds.tds_types.BaseTypeSerializerN(size)[source]

Base type for nullable TDS data types.

All nullable TDS types should derive from it. In addition actual types should provide the following:

  • type - class variable storing type identifier

  • subtypes - class variable storing dict {subtype_size: subtype_instance}

classmethod from_stream(r)[source]

Class method that reads and returns a type instance.

Parameters:

r – An instance of _TdsReader to read type from.

Should be implemented in actual types.

get_typeid()[source]

Returns type identifier of type.

read(r)[source]

Reads value from the stream.

Parameters:

r – An instance of _TdsReader to read value from.

Returns:

A read value.

Should be implemented in actual types.

write(w, val)[source]

Writes type’s value into stream

Parameters:
  • w – An instance of _TdsWriter to write into.

  • value – A value to be stored, should be compatible with the type

Should be implemented in actual types.

write_info(w)[source]

Writes type info into w stream.

Parameters:

w – An instance of _TdsWriter to write into.

Should be symmetrical to from_stream method. Should be implemented in actual types.

class pytds.tds_types.BigIntSerializer(precision=None, scale=None, size=None)[source]
read(r)[source]

Reads value from the stream.

Parameters:

r – An instance of _TdsReader to read value from.

Returns:

A read value.

Should be implemented in actual types.

write(w, val)[source]

Writes type’s value into stream

Parameters:
  • w – An instance of _TdsWriter to write into.

  • value – A value to be stored, should be compatible with the type

Should be implemented in actual types.

class pytds.tds_types.Binary[source]
class pytds.tds_types.BitNSerializer(typ)[source]
class pytds.tds_types.BitSerializer(precision=None, scale=None, size=None)[source]
read(r)[source]

Reads value from the stream.

Parameters:

r – An instance of _TdsReader to read value from.

Returns:

A read value.

Should be implemented in actual types.

write(w, value)[source]

Writes type’s value into stream

Parameters:
  • w – An instance of _TdsWriter to write into.

  • value – A value to be stored, should be compatible with the type

Should be implemented in actual types.

class pytds.tds_types.DateTime(days, time_part)[source]

Corresponds to MSSQL datetime

class pytds.tds_types.DateTime2Serializer(typ)[source]
classmethod from_stream(r)[source]

Class method that reads and returns a type instance.

Parameters:

r – An instance of _TdsReader to read type from.

Should be implemented in actual types.

read(r)[source]

Reads value from the stream.

Parameters:

r – An instance of _TdsReader to read value from.

Returns:

A read value.

Should be implemented in actual types.

write(w, value)[source]

Writes type’s value into stream

Parameters:
  • w – An instance of _TdsWriter to write into.

  • value – A value to be stored, should be compatible with the type

Should be implemented in actual types.

write_info(w)[source]

Writes type info into w stream.

Parameters:

w – An instance of _TdsWriter to write into.

Should be symmetrical to from_stream method. Should be implemented in actual types.

class pytds.tds_types.DateTimeNSerializer(size)[source]
class pytds.tds_types.DateTimeOffsetSerializer(typ)[source]
classmethod from_stream(r)[source]

Class method that reads and returns a type instance.

Parameters:

r – An instance of _TdsReader to read type from.

Should be implemented in actual types.

read(r)[source]

Reads value from the stream.

Parameters:

r – An instance of _TdsReader to read value from.

Returns:

A read value.

Should be implemented in actual types.

write(w, value)[source]

Writes type’s value into stream

Parameters:
  • w – An instance of _TdsWriter to write into.

  • value – A value to be stored, should be compatible with the type

Should be implemented in actual types.

write_info(w)[source]

Writes type info into w stream.

Parameters:

w – An instance of _TdsWriter to write into.

Should be symmetrical to from_stream method. Should be implemented in actual types.

class pytds.tds_types.DateTimeSerializer(precision=None, scale=None, size=None)[source]
read(r)[source]

Reads value from the stream.

Parameters:

r – An instance of _TdsReader to read value from.

Returns:

A read value.

Should be implemented in actual types.

write(w, val)[source]

Writes type’s value into stream

Parameters:
  • w – An instance of _TdsWriter to write into.

  • value – A value to be stored, should be compatible with the type

Should be implemented in actual types.

class pytds.tds_types.FloatNSerializer(size)[source]
class pytds.tds_types.FloatSerializer(precision=None, scale=None, size=None)[source]
read(r)[source]

Reads value from the stream.

Parameters:

r – An instance of _TdsReader to read value from.

Returns:

A read value.

Should be implemented in actual types.

write(w, val)[source]

Writes type’s value into stream

Parameters:
  • w – An instance of _TdsWriter to write into.

  • value – A value to be stored, should be compatible with the type

Should be implemented in actual types.

class pytds.tds_types.Image70Serializer(size=0, table_name='')[source]
classmethod from_stream(r)[source]

Class method that reads and returns a type instance.

Parameters:

r – An instance of _TdsReader to read type from.

Should be implemented in actual types.

read(r)[source]

Reads value from the stream.

Parameters:

r – An instance of _TdsReader to read value from.

Returns:

A read value.

Should be implemented in actual types.

write(w, val)[source]

Writes type’s value into stream

Parameters:
  • w – An instance of _TdsWriter to write into.

  • value – A value to be stored, should be compatible with the type

Should be implemented in actual types.

write_info(w)[source]

Writes type info into w stream.

Parameters:

w – An instance of _TdsWriter to write into.

Should be symmetrical to from_stream method. Should be implemented in actual types.

class pytds.tds_types.Image72Serializer(size=0, parts=())[source]
classmethod from_stream(r)[source]

Class method that reads and returns a type instance.

Parameters:

r – An instance of _TdsReader to read type from.

Should be implemented in actual types.

class pytds.tds_types.IntNSerializer(typ)[source]
classmethod from_stream(r)[source]

Class method that reads and returns a type instance.

Parameters:

r – An instance of _TdsReader to read type from.

Should be implemented in actual types.

class pytds.tds_types.IntSerializer(precision=None, scale=None, size=None)[source]
read(r)[source]

Reads value from the stream.

Parameters:

r – An instance of _TdsReader to read value from.

Returns:

A read value.

Should be implemented in actual types.

write(w, val)[source]

Writes type’s value into stream

Parameters:
  • w – An instance of _TdsWriter to write into.

  • value – A value to be stored, should be compatible with the type

Should be implemented in actual types.

class pytds.tds_types.IntType[source]

Integer type, corresponds to INT type in the MSSQL server.

class pytds.tds_types.Money4Serializer(precision=None, scale=None, size=None)[source]
read(r)[source]

Reads value from the stream.

Parameters:

r – An instance of _TdsReader to read value from.

Returns:

A read value.

Should be implemented in actual types.

write(w, val)[source]

Writes type’s value into stream

Parameters:
  • w – An instance of _TdsWriter to write into.

  • value – A value to be stored, should be compatible with the type

Should be implemented in actual types.

class pytds.tds_types.Money8Serializer(precision=None, scale=None, size=None)[source]
read(r)[source]

Reads value from the stream.

Parameters:

r – An instance of _TdsReader to read value from.

Returns:

A read value.

Should be implemented in actual types.

write(w, val)[source]

Writes type’s value into stream

Parameters:
  • w – An instance of _TdsWriter to write into.

  • value – A value to be stored, should be compatible with the type

Should be implemented in actual types.

class pytds.tds_types.MoneyNSerializer(size)[source]
class pytds.tds_types.MsDateSerializer(typ)[source]
classmethod from_stream(r)[source]

Class method that reads and returns a type instance.

Parameters:

r – An instance of _TdsReader to read type from.

Should be implemented in actual types.

read(r)[source]

Reads value from the stream.

Parameters:

r – An instance of _TdsReader to read value from.

Returns:

A read value.

Should be implemented in actual types.

write(w, value)[source]

Writes type’s value into stream

Parameters:
  • w – An instance of _TdsWriter to write into.

  • value – A value to be stored, should be compatible with the type

Should be implemented in actual types.

class pytds.tds_types.MsDecimalSerializer(precision=18, scale=0)[source]
classmethod from_stream(r)[source]

Class method that reads and returns a type instance.

Parameters:

r – An instance of _TdsReader to read type from.

Should be implemented in actual types.

read(r)[source]

Reads value from the stream.

Parameters:

r – An instance of _TdsReader to read value from.

Returns:

A read value.

Should be implemented in actual types.

write(w, value)[source]

Writes type’s value into stream

Parameters:
  • w – An instance of _TdsWriter to write into.

  • value – A value to be stored, should be compatible with the type

Should be implemented in actual types.

write_info(w)[source]

Writes type info into w stream.

Parameters:

w – An instance of _TdsWriter to write into.

Should be symmetrical to from_stream method. Should be implemented in actual types.

class pytds.tds_types.MsTimeSerializer(typ)[source]
classmethod from_stream(r)[source]

Class method that reads and returns a type instance.

Parameters:

r – An instance of _TdsReader to read type from.

Should be implemented in actual types.

read(r)[source]

Reads value from the stream.

Parameters:

r – An instance of _TdsReader to read value from.

Returns:

A read value.

Should be implemented in actual types.

write(w, value)[source]

Writes type’s value into stream

Parameters:
  • w – An instance of _TdsWriter to write into.

  • value – A value to be stored, should be compatible with the type

Should be implemented in actual types.

write_info(w)[source]

Writes type info into w stream.

Parameters:

w – An instance of _TdsWriter to write into.

Should be symmetrical to from_stream method. Should be implemented in actual types.

class pytds.tds_types.MsUniqueSerializer(precision=None, scale=None, size=None)[source]
classmethod from_stream(r)[source]

Class method that reads and returns a type instance.

Parameters:

r – An instance of _TdsReader to read type from.

Should be implemented in actual types.

read(r)[source]

Reads value from the stream.

Parameters:

r – An instance of _TdsReader to read value from.

Returns:

A read value.

Should be implemented in actual types.

write(w, value)[source]

Writes type’s value into stream

Parameters:
  • w – An instance of _TdsWriter to write into.

  • value – A value to be stored, should be compatible with the type

Should be implemented in actual types.

write_info(w)[source]

Writes type info into w stream.

Parameters:

w – An instance of _TdsWriter to write into.

Should be symmetrical to from_stream method. Should be implemented in actual types.

class pytds.tds_types.NText70Serializer(size=0, table_name='', collation=Collation(lcid=0, sort_id=0, ignore_case=0, ignore_accent=0, ignore_width=0, ignore_kana=0, binary=0, binary2=0, version=0))[source]
classmethod from_stream(r)[source]

Class method that reads and returns a type instance.

Parameters:

r – An instance of _TdsReader to read type from.

Should be implemented in actual types.

read(r)[source]

Reads value from the stream.

Parameters:

r – An instance of _TdsReader to read value from.

Returns:

A read value.

Should be implemented in actual types.

write(w, val)[source]

Writes type’s value into stream

Parameters:
  • w – An instance of _TdsWriter to write into.

  • value – A value to be stored, should be compatible with the type

Should be implemented in actual types.

write_info(w)[source]

Writes type info into w stream.

Parameters:

w – An instance of _TdsWriter to write into.

Should be symmetrical to from_stream method. Should be implemented in actual types.

class pytds.tds_types.NText71Serializer(size=0, table_name='', collation=Collation(lcid=0, sort_id=0, ignore_case=0, ignore_accent=0, ignore_width=0, ignore_kana=0, binary=0, binary2=0, version=0))[source]
classmethod from_stream(r)[source]

Class method that reads and returns a type instance.

Parameters:

r – An instance of _TdsReader to read type from.

Should be implemented in actual types.

write_info(w)[source]

Writes type info into w stream.

Parameters:

w – An instance of _TdsWriter to write into.

Should be symmetrical to from_stream method. Should be implemented in actual types.

class pytds.tds_types.NText72Serializer(size=0, table_name_parts=(), collation=Collation(lcid=0, sort_id=0, ignore_case=0, ignore_accent=0, ignore_width=0, ignore_kana=0, binary=0, binary2=0, version=0))[source]
classmethod from_stream(r)[source]

Class method that reads and returns a type instance.

Parameters:

r – An instance of _TdsReader to read type from.

Should be implemented in actual types.

class pytds.tds_types.NVarChar70Serializer(size, collation=Collation(lcid=0, sort_id=0, ignore_case=0, ignore_accent=0, ignore_width=0, ignore_kana=0, binary=0, binary2=0, version=0))[source]
classmethod from_stream(r)[source]

Class method that reads and returns a type instance.

Parameters:

r – An instance of _TdsReader to read type from.

Should be implemented in actual types.

read(r)[source]

Reads value from the stream.

Parameters:

r – An instance of _TdsReader to read value from.

Returns:

A read value.

Should be implemented in actual types.

write(w, val)[source]

Writes type’s value into stream

Parameters:
  • w – An instance of _TdsWriter to write into.

  • value – A value to be stored, should be compatible with the type

Should be implemented in actual types.

write_info(w)[source]

Writes type info into w stream.

Parameters:

w – An instance of _TdsWriter to write into.

Should be symmetrical to from_stream method. Should be implemented in actual types.

class pytds.tds_types.NVarChar71Serializer(size, collation=Collation(lcid=0, sort_id=0, ignore_case=0, ignore_accent=0, ignore_width=0, ignore_kana=0, binary=0, binary2=0, version=0))[source]
classmethod from_stream(r)[source]

Class method that reads and returns a type instance.

Parameters:

r – An instance of _TdsReader to read type from.

Should be implemented in actual types.

write_info(w)[source]

Writes type info into w stream.

Parameters:

w – An instance of _TdsWriter to write into.

Should be symmetrical to from_stream method. Should be implemented in actual types.

class pytds.tds_types.NVarChar72Serializer(size, collation=Collation(lcid=0, sort_id=0, ignore_case=0, ignore_accent=0, ignore_width=0, ignore_kana=0, binary=0, binary2=0, version=0))[source]
classmethod from_stream(r)[source]

Class method that reads and returns a type instance.

Parameters:

r – An instance of _TdsReader to read type from.

Should be implemented in actual types.

class pytds.tds_types.NVarCharMaxSerializer(collation=Collation(lcid=0, sort_id=0, ignore_case=0, ignore_accent=0, ignore_width=0, ignore_kana=0, binary=0, binary2=0, version=0))[source]
get_typeid()[source]

Returns type identifier of type.

read(r)[source]

Reads value from the stream.

Parameters:

r – An instance of _TdsReader to read value from.

Returns:

A read value.

Should be implemented in actual types.

write(w, val)[source]

Writes type’s value into stream

Parameters:
  • w – An instance of _TdsWriter to write into.

  • value – A value to be stored, should be compatible with the type

Should be implemented in actual types.

write_info(w)[source]

Writes type info into w stream.

Parameters:

w – An instance of _TdsWriter to write into.

Should be symmetrical to from_stream method. Should be implemented in actual types.

class pytds.tds_types.PlpReader(r)[source]

Partially length prefixed reader

Spec: http://msdn.microsoft.com/en-us/library/dd340469.aspx

chunks()[source]

Generates chunks from stream, each chunk is an instace of bytes.

is_null()[source]
Returns:

True if stored value is NULL

is_unknown_len()[source]
Returns:

True if total size is unknown upfront

size()[source]
Returns:

Total size in bytes if is_uknown_len and is_null are both False

class pytds.tds_types.RealSerializer(precision=None, scale=None, size=None)[source]
read(r)[source]

Reads value from the stream.

Parameters:

r – An instance of _TdsReader to read value from.

Returns:

A read value.

Should be implemented in actual types.

write(w, val)[source]

Writes type’s value into stream

Parameters:
  • w – An instance of _TdsWriter to write into.

  • value – A value to be stored, should be compatible with the type

Should be implemented in actual types.

class pytds.tds_types.SerializerFactory(tds_ver)[source]

Factory class for TDS data types

class pytds.tds_types.SmallDateTime(days, minutes)[source]

Corresponds to MSSQL smalldatetime

class pytds.tds_types.SmallDateTimeSerializer(precision=None, scale=None, size=None)[source]
read(r)[source]

Reads value from the stream.

Parameters:

r – An instance of _TdsReader to read value from.

Returns:

A read value.

Should be implemented in actual types.

write(w, val)[source]

Writes type’s value into stream

Parameters:
  • w – An instance of _TdsWriter to write into.

  • value – A value to be stored, should be compatible with the type

Should be implemented in actual types.

class pytds.tds_types.SmallIntSerializer(precision=None, scale=None, size=None)[source]
read(r)[source]

Reads value from the stream.

Parameters:

r – An instance of _TdsReader to read value from.

Returns:

A read value.

Should be implemented in actual types.

write(w, val)[source]

Writes type’s value into stream

Parameters:
  • w – An instance of _TdsWriter to write into.

  • value – A value to be stored, should be compatible with the type

Should be implemented in actual types.

class pytds.tds_types.TableSerializer(table_type, columns_serializers)[source]

Used to serialize table valued parameters

spec: https://msdn.microsoft.com/en-us/library/dd304813.aspx

classmethod from_stream(r)[source]

According to spec TDS does not support output TVP values

read(r)[source]

According to spec TDS does not support output TVP values

write(w, val)[source]

Writes remaining part of TVP_TYPE_INFO structure, resuming from TVP_COLMETADATA

specs: https://msdn.microsoft.com/en-us/library/dd302994.aspx https://msdn.microsoft.com/en-us/library/dd305261.aspx https://msdn.microsoft.com/en-us/library/dd303230.aspx

@param w: TdsWriter @param val: TableValuedParam or None @return:

write_info(w)[source]

Writes TVP_TYPENAME structure

spec: https://msdn.microsoft.com/en-us/library/dd302994.aspx @param w: TdsWriter @return:

class pytds.tds_types.TableType(typ_schema, typ_name, columns)[source]

Used to serialize table valued parameters

spec: https://msdn.microsoft.com/en-us/library/dd304813.aspx

class pytds.tds_types.TableValuedParam(type_name=None, columns=None, rows=None)[source]

Used to represent a value of table-valued parameter

class pytds.tds_types.Text70Serializer(size=0, table_name='', collation=Collation(lcid=0, sort_id=0, ignore_case=0, ignore_accent=0, ignore_width=0, ignore_kana=0, binary=0, binary2=0, version=0), codec=None)[source]
classmethod from_stream(r)[source]

Class method that reads and returns a type instance.

Parameters:

r – An instance of _TdsReader to read type from.

Should be implemented in actual types.

read(r)[source]

Reads value from the stream.

Parameters:

r – An instance of _TdsReader to read value from.

Returns:

A read value.

Should be implemented in actual types.

write(w, val)[source]

Writes type’s value into stream

Parameters:
  • w – An instance of _TdsWriter to write into.

  • value – A value to be stored, should be compatible with the type

Should be implemented in actual types.

write_info(w)[source]

Writes type info into w stream.

Parameters:

w – An instance of _TdsWriter to write into.

Should be symmetrical to from_stream method. Should be implemented in actual types.

class pytds.tds_types.Text71Serializer(size=0, table_name='', collation=Collation(lcid=0, sort_id=0, ignore_case=0, ignore_accent=0, ignore_width=0, ignore_kana=0, binary=0, binary2=0, version=0), codec=None)[source]
classmethod from_stream(r)[source]

Class method that reads and returns a type instance.

Parameters:

r – An instance of _TdsReader to read type from.

Should be implemented in actual types.

write_info(w)[source]

Writes type info into w stream.

Parameters:

w – An instance of _TdsWriter to write into.

Should be symmetrical to from_stream method. Should be implemented in actual types.

class pytds.tds_types.Text72Serializer(size=0, table_name_parts=(), collation=Collation(lcid=0, sort_id=0, ignore_case=0, ignore_accent=0, ignore_width=0, ignore_kana=0, binary=0, binary2=0, version=0))[source]
classmethod from_stream(r)[source]

Class method that reads and returns a type instance.

Parameters:

r – An instance of _TdsReader to read type from.

Should be implemented in actual types.

class pytds.tds_types.TinyIntSerializer(precision=None, scale=None, size=None)[source]
read(r)[source]

Reads value from the stream.

Parameters:

r – An instance of _TdsReader to read value from.

Returns:

A read value.

Should be implemented in actual types.

write(w, val)[source]

Writes type’s value into stream

Parameters:
  • w – An instance of _TdsWriter to write into.

  • value – A value to be stored, should be compatible with the type

Should be implemented in actual types.

class pytds.tds_types.UDT72Serializer(max_byte_size, db_name, schema_name, type_name, assembly_qualified_name)[source]
classmethod from_stream(r)[source]

Class method that reads and returns a type instance.

Parameters:

r – An instance of _TdsReader to read type from.

Should be implemented in actual types.

read(r)[source]

Reads value from the stream.

Parameters:

r – An instance of _TdsReader to read value from.

Returns:

A read value.

Should be implemented in actual types.

class pytds.tds_types.UDT72SerializerMax(*args, **kwargs)[source]
class pytds.tds_types.VarBinarySerializer(size)[source]
classmethod from_stream(r)[source]

Class method that reads and returns a type instance.

Parameters:

r – An instance of _TdsReader to read type from.

Should be implemented in actual types.

read(r)[source]

Reads value from the stream.

Parameters:

r – An instance of _TdsReader to read value from.

Returns:

A read value.

Should be implemented in actual types.

write(w, val)[source]

Writes type’s value into stream

Parameters:
  • w – An instance of _TdsWriter to write into.

  • value – A value to be stored, should be compatible with the type

Should be implemented in actual types.

write_info(w)[source]

Writes type info into w stream.

Parameters:

w – An instance of _TdsWriter to write into.

Should be symmetrical to from_stream method. Should be implemented in actual types.

class pytds.tds_types.VarBinarySerializer72(size)[source]
classmethod from_stream(r)[source]

Class method that reads and returns a type instance.

Parameters:

r – An instance of _TdsReader to read type from.

Should be implemented in actual types.

class pytds.tds_types.VarBinarySerializerMax[source]
read(r)[source]

Reads value from the stream.

Parameters:

r – An instance of _TdsReader to read value from.

Returns:

A read value.

Should be implemented in actual types.

write(w, val)[source]

Writes type’s value into stream

Parameters:
  • w – An instance of _TdsWriter to write into.

  • value – A value to be stored, should be compatible with the type

Should be implemented in actual types.

write_info(w)[source]

Writes type info into w stream.

Parameters:

w – An instance of _TdsWriter to write into.

Should be symmetrical to from_stream method. Should be implemented in actual types.

class pytds.tds_types.VarChar70Serializer(size, collation=Collation(lcid=0, sort_id=0, ignore_case=0, ignore_accent=0, ignore_width=0, ignore_kana=0, binary=0, binary2=0, version=0), codec=None)[source]
classmethod from_stream(r)[source]

Class method that reads and returns a type instance.

Parameters:

r – An instance of _TdsReader to read type from.

Should be implemented in actual types.

read(r)[source]

Reads value from the stream.

Parameters:

r – An instance of _TdsReader to read value from.

Returns:

A read value.

Should be implemented in actual types.

write(w, val)[source]

Writes type’s value into stream

Parameters:
  • w – An instance of _TdsWriter to write into.

  • value – A value to be stored, should be compatible with the type

Should be implemented in actual types.

write_info(w)[source]

Writes type info into w stream.

Parameters:

w – An instance of _TdsWriter to write into.

Should be symmetrical to from_stream method. Should be implemented in actual types.

class pytds.tds_types.VarChar71Serializer(size, collation=Collation(lcid=0, sort_id=0, ignore_case=0, ignore_accent=0, ignore_width=0, ignore_kana=0, binary=0, binary2=0, version=0), codec=None)[source]
classmethod from_stream(r)[source]

Class method that reads and returns a type instance.

Parameters:

r – An instance of _TdsReader to read type from.

Should be implemented in actual types.

write_info(w)[source]

Writes type info into w stream.

Parameters:

w – An instance of _TdsWriter to write into.

Should be symmetrical to from_stream method. Should be implemented in actual types.

class pytds.tds_types.VarChar72Serializer(size, collation=Collation(lcid=0, sort_id=0, ignore_case=0, ignore_accent=0, ignore_width=0, ignore_kana=0, binary=0, binary2=0, version=0), codec=None)[source]
classmethod from_stream(r)[source]

Class method that reads and returns a type instance.

Parameters:

r – An instance of _TdsReader to read type from.

Should be implemented in actual types.

class pytds.tds_types.VarCharMaxSerializer(collation=Collation(lcid=0, sort_id=0, ignore_case=0, ignore_accent=0, ignore_width=0, ignore_kana=0, binary=0, binary2=0, version=0))[source]
read(r)[source]

Reads value from the stream.

Parameters:

r – An instance of _TdsReader to read value from.

Returns:

A read value.

Should be implemented in actual types.

write(w, val)[source]

Writes type’s value into stream

Parameters:
  • w – An instance of _TdsWriter to write into.

  • value – A value to be stored, should be compatible with the type

Should be implemented in actual types.

write_info(w)[source]

Writes type info into w stream.

Parameters:

w – An instance of _TdsWriter to write into.

Should be symmetrical to from_stream method. Should be implemented in actual types.

class pytds.tds_types.VariantSerializer(precision=None, scale=None, size=None)[source]
classmethod from_stream(r)[source]

Class method that reads and returns a type instance.

Parameters:

r – An instance of _TdsReader to read type from.

Should be implemented in actual types.

read(r)[source]

Reads value from the stream.

Parameters:

r – An instance of _TdsReader to read value from.

Returns:

A read value.

Should be implemented in actual types.

write(w, val)[source]

Writes type’s value into stream

Parameters:
  • w – An instance of _TdsWriter to write into.

  • value – A value to be stored, should be compatible with the type

Should be implemented in actual types.

write_info(w)[source]

Writes type info into w stream.

Parameters:

w – An instance of _TdsWriter to write into.

Should be symmetrical to from_stream method. Should be implemented in actual types.

class pytds.tds_types.XmlSerializer(schema=None)[source]
classmethod from_stream(r)[source]

Class method that reads and returns a type instance.

Parameters:

r – An instance of _TdsReader to read type from.

Should be implemented in actual types.

get_typeid()[source]

Returns type identifier of type.

write_info(w)[source]

Writes type info into w stream.

Parameters:

w – An instance of _TdsWriter to write into.

Should be symmetrical to from_stream method. Should be implemented in actual types.

pytds.tz – timezones

class pytds.tz.FixedOffsetTimezone(offset: float, name: str | None = None)[source]

Fixed offset in minutes east from UTC.

dst(dt: datetime | None) timedelta[source]

datetime -> DST offset as timedelta positive east of UTC.

tzname(dt: datetime | None) str | None[source]

datetime -> string name of time zone.

utcoffset(dt: datetime | None) timedelta[source]

datetime -> timedelta showing offset from UTC, negative values indicating West of UTC

class pytds.tz.LocalTimezone[source]
dst(dt: datetime | None) timedelta[source]

datetime -> DST offset as timedelta positive east of UTC.

tzname(dt: datetime | None) str[source]

datetime -> string name of time zone.

utcoffset(dt: datetime | None) timedelta[source]

datetime -> timedelta showing offset from UTC, negative values indicating West of UTC