pymssql module reference

python > pymssql module reference
27.04.2018 15:25:43

Наиболее часто встречающиеся слова в статье:

[connect] [database] [pymssql] [windows] [connection] [timeout] [default] [FreeTDS] [seconds] [version]


Module-level symbols

Constants, required by the DB-API 2.0 (PEP 249) specification.


''2.0''  pymssql strives for compliance with DB-API 2.0.


''pyformat''  pymssql uses extended python format codes.


1 – Module may be shared, but not connections.


pymssql.connect(server=''.'', user='''', password='''', database='''', timeout=0, login_timeout=60, charset=''UTF-8'', as_dict=False, host='''', appname=None, port=''1433'', conn_properties, autocommit=False, tds_version=''7.1'')

Constructor for creating a connection to the database. Returns a Connection object.

  • server (str) – database host
  • user (str) – database user to connect as
  • password (str) – user’s password
  • database (str) – the database to initially connect to
  • timeout (int) – query timeout in seconds, default 0 (no timeout)
  • login_timeout (int) – timeout for connection and login in seconds, default 60
  • charset (str) – character set with which to connect to the database
  • conn_properties – SQL queries to send to the server upon connection establishment. Can be a string or another kind of iterable of strings. Default value: See _mssql.connect()
  • as_dict (bool) – whether rows should be returned as dictionaries instead of tuples
  • appname (str) – Set the application name to use for the connection
  • port (str) – the TCP port to use to connect to the server
  • autocommit (bool) – Whether to use default autocommiting mode or not
  • tds_version (str) – TDS protocol version to use.


Currently, setting timeout or login_timeout has a process-wide effect because the FreeTDS db-lib API functions used to implement such timeouts have a global effect.


If you need to connect to Azure:

  • Use FreeTDS 0.91 or newer
  • Use TDS 7.1 or newer
  • Make sure FreeTDS is built with SSL support
  • Specify the database name you are connecting to in the connect() call
  • Specify the username in username@servername form in the connect() call


pymssql.connect("", "", "password", "db_name")


pymssql.connect("myalias", "", "password", "db_name")

if you’ve defined myalias in the freetds.conf FreeTDS config file:

host =
tds version = 7.1