JezK
Edit File: config.html
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" /> <title>Configuration — Alembic 1.8.1 documentation</title> <link rel="stylesheet" type="text/css" href="../_static/pygments.css" /> <link rel="stylesheet" type="text/css" href="../_static/nature_override.css" /> <link rel="stylesheet" type="text/css" href="../_static/copybutton.css" /> <link rel="stylesheet" type="text/css" href="../_static/changelog.css" /> <link rel="stylesheet" type="text/css" href="../_static/sphinx_paramlinks.css" /> <script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js"></script> <script src="../_static/jquery.js"></script> <script src="../_static/underscore.js"></script> <script src="../_static/doctools.js"></script> <script src="../_static/clipboard.min.js"></script> <script src="../_static/copybutton.js"></script> <link rel="index" title="Index" href="../genindex.html" /> <link rel="search" title="Search" href="../search.html" /> <link rel="next" title="Commands" href="commands.html" /> <link rel="prev" title="Runtime Objects" href="runtime.html" /> </head><body> <div class="related" role="navigation" aria-label="related navigation"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="General Index" accesskey="I">index</a></li> <li class="right" > <a href="../py-modindex.html" title="Python Module Index" >modules</a> |</li> <li class="right" > <a href="commands.html" title="Commands" accesskey="N">next</a> |</li> <li class="right" > <a href="runtime.html" title="Runtime Objects" accesskey="P">previous</a> |</li> <li class="nav-item nav-item-0"><a href="../index.html">Alembic 1.8.1 documentation</a> »</li> <li class="nav-item nav-item-1"><a href="index.html" accesskey="U">API Details</a> »</li> <li class="nav-item nav-item-this"><a href="">Configuration</a></li> </ul> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body" role="main"> <section id="configuration"> <span id="alembic-config-toplevel"></span><h1>Configuration<a class="headerlink" href="#configuration" title="Permalink to this headline">¶</a></h1> <div class="admonition note"> <p class="admonition-title">Note</p> <p>this section discusses the <strong>internal API of Alembic</strong> as regards internal configuration constructs. This section is only useful for developers who wish to extend the capabilities of Alembic. For documentation on configuration of an Alembic environment, please see <a class="reference internal" href="../tutorial.html"><span class="doc">Tutorial</span></a>.</p> </div> <p>The <a class="reference internal" href="#alembic.config.Config" title="alembic.config.Config"><code class="xref py py-class docutils literal notranslate"><span class="pre">Config</span></code></a> object represents the configuration passed to the Alembic environment. From an API usage perspective, it is needed for the following use cases:</p> <ul class="simple"> <li><p>to create a <a class="reference internal" href="script.html#alembic.script.ScriptDirectory" title="alembic.script.ScriptDirectory"><code class="xref py py-class docutils literal notranslate"><span class="pre">ScriptDirectory</span></code></a>, which allows you to work with the actual script files in a migration environment</p></li> <li><p>to create an <a class="reference internal" href="runtime.html#alembic.runtime.environment.EnvironmentContext" title="alembic.runtime.environment.EnvironmentContext"><code class="xref py py-class docutils literal notranslate"><span class="pre">EnvironmentContext</span></code></a>, which allows you to actually run the <code class="docutils literal notranslate"><span class="pre">env.py</span></code> module within the migration environment</p></li> <li><p>to programmatically run any of the commands in the <a class="reference internal" href="commands.html#alembic-command-toplevel"><span class="std std-ref">Commands</span></a> module.</p></li> </ul> <p>The <a class="reference internal" href="#alembic.config.Config" title="alembic.config.Config"><code class="xref py py-class docutils literal notranslate"><span class="pre">Config</span></code></a> is <em>not</em> needed for these cases:</p> <ul class="simple"> <li><p>to instantiate a <a class="reference internal" href="runtime.html#alembic.runtime.migration.MigrationContext" title="alembic.runtime.migration.MigrationContext"><code class="xref py py-class docutils literal notranslate"><span class="pre">MigrationContext</span></code></a> directly - this object only needs a SQLAlchemy connection or dialect name.</p></li> <li><p>to instantiate a <a class="reference internal" href="../ops.html#alembic.operations.Operations" title="alembic.operations.Operations"><code class="xref py py-class docutils literal notranslate"><span class="pre">Operations</span></code></a> object - this object only needs a <a class="reference internal" href="runtime.html#alembic.runtime.migration.MigrationContext" title="alembic.runtime.migration.MigrationContext"><code class="xref py py-class docutils literal notranslate"><span class="pre">MigrationContext</span></code></a>.</p></li> </ul> <span class="target" id="module-alembic.config"></span><dl class="py class"> <dt class="sig sig-object py" id="alembic.config.Config"> <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">alembic.config.</span></span><span class="sig-name descname"><span class="pre">Config</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">file_:</span> <span class="pre">typing.Optional[str]</span> <span class="pre">=</span> <span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">ini_section:</span> <span class="pre">str</span> <span class="pre">=</span> <span class="pre">'alembic'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">output_buffer:</span> <span class="pre">typing.Optional[typing.TextIO]</span> <span class="pre">=</span> <span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">stdout:</span> <span class="pre">typing.TextIO</span> <span class="pre">=</span> <span class="pre"><_io.TextIOWrapper</span> <span class="pre">name='<stdout>'</span> <span class="pre">mode='w'</span> <span class="pre">encoding='utf-8'></span></span></em>, <em class="sig-param"><span class="n"><span class="pre">cmd_opts:</span> <span class="pre">typing.Optional[argparse.Namespace]</span> <span class="pre">=</span> <span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">config_args:</span> <span class="pre">sqlalchemy.util._collections._immutabledict_py_fallback.<locals>.immutabledict</span> <span class="pre">=</span> <span class="pre">{}</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">attributes:</span> <span class="pre">typing.Optional[dict]</span> <span class="pre">=</span> <span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.config.Config" title="Permalink to this definition">¶</a></dt> <dd><p>Represent an Alembic configuration.</p> <p>Within an <code class="docutils literal notranslate"><span class="pre">env.py</span></code> script, this is available via the <a class="reference internal" href="runtime.html#alembic.runtime.environment.EnvironmentContext.config" title="alembic.runtime.environment.EnvironmentContext.config"><code class="xref py py-attr docutils literal notranslate"><span class="pre">EnvironmentContext.config</span></code></a> attribute, which in turn is available at <code class="docutils literal notranslate"><span class="pre">alembic.context</span></code>:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">alembic</span> <span class="kn">import</span> <span class="n">context</span> <span class="n">some_param</span> <span class="o">=</span> <span class="n">context</span><span class="o">.</span><span class="n">config</span><span class="o">.</span><span class="n">get_main_option</span><span class="p">(</span><span class="s2">"my option"</span><span class="p">)</span> </pre></div> </div> <p>When invoking Alembic programatically, a new <a class="reference internal" href="#alembic.config.Config" title="alembic.config.Config"><code class="xref py py-class docutils literal notranslate"><span class="pre">Config</span></code></a> can be created by passing the name of an .ini file to the constructor:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">alembic.config</span> <span class="kn">import</span> <span class="n">Config</span> <span class="n">alembic_cfg</span> <span class="o">=</span> <span class="n">Config</span><span class="p">(</span><span class="s2">"/path/to/yourapp/alembic.ini"</span><span class="p">)</span> </pre></div> </div> <p>With a <a class="reference internal" href="#alembic.config.Config" title="alembic.config.Config"><code class="xref py py-class docutils literal notranslate"><span class="pre">Config</span></code></a> object, you can then run Alembic commands programmatically using the directives in <a class="reference internal" href="commands.html#module-alembic.command" title="alembic.command"><code class="xref py py-mod docutils literal notranslate"><span class="pre">alembic.command</span></code></a>.</p> <p>The <a class="reference internal" href="#alembic.config.Config" title="alembic.config.Config"><code class="xref py py-class docutils literal notranslate"><span class="pre">Config</span></code></a> object can also be constructed without a filename. Values can be set programmatically, and new sections will be created as needed:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">alembic.config</span> <span class="kn">import</span> <span class="n">Config</span> <span class="n">alembic_cfg</span> <span class="o">=</span> <span class="n">Config</span><span class="p">()</span> <span class="n">alembic_cfg</span><span class="o">.</span><span class="n">set_main_option</span><span class="p">(</span><span class="s2">"script_location"</span><span class="p">,</span> <span class="s2">"myapp:migrations"</span><span class="p">)</span> <span class="n">alembic_cfg</span><span class="o">.</span><span class="n">set_main_option</span><span class="p">(</span><span class="s2">"sqlalchemy.url"</span><span class="p">,</span> <span class="s2">"postgresql://foo/bar"</span><span class="p">)</span> <span class="n">alembic_cfg</span><span class="o">.</span><span class="n">set_section_option</span><span class="p">(</span><span class="s2">"mysection"</span><span class="p">,</span> <span class="s2">"foo"</span><span class="p">,</span> <span class="s2">"bar"</span><span class="p">)</span> </pre></div> </div> <div class="admonition warning"> <p class="admonition-title">Warning</p> <p>When using programmatic configuration, make sure the <code class="docutils literal notranslate"><span class="pre">env.py</span></code> file in use is compatible with the target configuration; including that the call to Python <code class="docutils literal notranslate"><span class="pre">logging.fileConfig()</span></code> is omitted if the programmatic configuration doesn’t actually include logging directives.</p> </div> <p>For passing non-string values to environments, such as connections and engines, use the <a class="reference internal" href="#alembic.config.Config.attributes" title="alembic.config.Config.attributes"><code class="xref py py-attr docutils literal notranslate"><span class="pre">Config.attributes</span></code></a> dictionary:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">with</span> <span class="n">engine</span><span class="o">.</span><span class="n">begin</span><span class="p">()</span> <span class="k">as</span> <span class="n">connection</span><span class="p">:</span> <span class="n">alembic_cfg</span><span class="o">.</span><span class="n">attributes</span><span class="p">[</span><span class="s1">'connection'</span><span class="p">]</span> <span class="o">=</span> <span class="n">connection</span> <span class="n">command</span><span class="o">.</span><span class="n">upgrade</span><span class="p">(</span><span class="n">alembic_cfg</span><span class="p">,</span> <span class="s2">"head"</span><span class="p">)</span> </pre></div> </div> <dl class="field-list simple"> <dt class="field-odd">Parameters</dt> <dd class="field-odd"><ul class="simple"> <li><p><span class="target" id="alembic.config.Config.params.file_"></span><strong>file_</strong><a class="paramlink headerlink reference internal" href="#alembic.config.Config.params.file_">¶</a> – name of the .ini file to open.</p></li> <li><p><span class="target" id="alembic.config.Config.params.ini_section"></span><strong>ini_section</strong><a class="paramlink headerlink reference internal" href="#alembic.config.Config.params.ini_section">¶</a> – name of the main Alembic section within the .ini file</p></li> <li><p><span class="target" id="alembic.config.Config.params.output_buffer"></span><strong>output_buffer</strong><a class="paramlink headerlink reference internal" href="#alembic.config.Config.params.output_buffer">¶</a> – optional file-like input buffer which will be passed to the <a class="reference internal" href="runtime.html#alembic.runtime.migration.MigrationContext" title="alembic.runtime.migration.MigrationContext"><code class="xref py py-class docutils literal notranslate"><span class="pre">MigrationContext</span></code></a> - used to redirect the output of “offline generation” when using Alembic programmatically.</p></li> <li><p><span class="target" id="alembic.config.Config.params.stdout"></span><strong>stdout</strong><a class="paramlink headerlink reference internal" href="#alembic.config.Config.params.stdout">¶</a> – buffer where the “print” output of commands will be sent. Defaults to <code class="docutils literal notranslate"><span class="pre">sys.stdout</span></code>.</p></li> <li><p><span class="target" id="alembic.config.Config.params.config_args"></span><strong>config_args</strong><a class="paramlink headerlink reference internal" href="#alembic.config.Config.params.config_args">¶</a> – A dictionary of keys and values that will be used for substitution in the alembic config file. The dictionary as given is <strong>copied</strong> to a new one, stored locally as the attribute <code class="docutils literal notranslate"><span class="pre">.config_args</span></code>. When the <a class="reference internal" href="#alembic.config.Config.file_config" title="alembic.config.Config.file_config"><code class="xref py py-attr docutils literal notranslate"><span class="pre">Config.file_config</span></code></a> attribute is first invoked, the replacement variable <code class="docutils literal notranslate"><span class="pre">here</span></code> will be added to this dictionary before the dictionary is passed to <code class="docutils literal notranslate"><span class="pre">ConfigParser()</span></code> to parse the .ini file.</p></li> <li><p><span class="target" id="alembic.config.Config.params.attributes"></span><strong>attributes</strong><a class="paramlink headerlink reference internal" href="#alembic.config.Config.params.attributes">¶</a> – <p>optional dictionary of arbitrary Python keys/values, which will be populated into the <a class="reference internal" href="#alembic.config.Config.attributes" title="alembic.config.Config.attributes"><code class="xref py py-attr docutils literal notranslate"><span class="pre">Config.attributes</span></code></a> dictionary.</p> <div class="admonition seealso"> <p class="admonition-title">See also</p> <p><a class="reference internal" href="../cookbook.html#connection-sharing"><span class="std std-ref">Sharing a Connection across one or more programmatic migration commands</span></a></p> </div> </p></li> </ul> </dd> </dl> <p>Construct a new <a class="reference internal" href="#alembic.config.Config" title="alembic.config.Config"><code class="xref py py-class docutils literal notranslate"><span class="pre">Config</span></code></a></p> <dl class="py attribute"> <dt class="sig sig-object py" id="alembic.config.Config.attributes"> <span class="sig-name descname"><span class="pre">attributes</span></span><a class="headerlink" href="#alembic.config.Config.attributes" title="Permalink to this definition">¶</a></dt> <dd><p>A Python dictionary for storage of additional state.</p> <p>This is a utility dictionary which can include not just strings but engines, connections, schema objects, or anything else. Use this to pass objects into an env.py script, such as passing a <code class="xref py py-class docutils literal notranslate"><span class="pre">sqlalchemy.engine.base.Connection</span></code> when calling commands from <a class="reference internal" href="commands.html#module-alembic.command" title="alembic.command"><code class="xref py py-mod docutils literal notranslate"><span class="pre">alembic.command</span></code></a> programmatically.</p> <div class="admonition seealso"> <p class="admonition-title">See also</p> <p><a class="reference internal" href="../cookbook.html#connection-sharing"><span class="std std-ref">Sharing a Connection across one or more programmatic migration commands</span></a></p> <p><a class="reference internal" href="#alembic.config.Config.params.attributes" title="alembic.config.Config"><code class="xref py py-paramref docutils literal notranslate"><span class="pre">Config.attributes</span></code></a></p> </div> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="alembic.config.Config.cmd_opts"> <span class="sig-name descname"><span class="pre">cmd_opts</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="pre">Optional</span><span class="p"><span class="pre">[</span></span><span class="pre">argparse.Namespace</span><span class="p"><span class="pre">]</span></span></em><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">None</span></em><a class="headerlink" href="#alembic.config.Config.cmd_opts" title="Permalink to this definition">¶</a></dt> <dd><p>The command-line options passed to the <code class="docutils literal notranslate"><span class="pre">alembic</span></code> script.</p> <p>Within an <code class="docutils literal notranslate"><span class="pre">env.py</span></code> script this can be accessed via the <a class="reference internal" href="runtime.html#alembic.runtime.environment.EnvironmentContext.config" title="alembic.runtime.environment.EnvironmentContext.config"><code class="xref py py-attr docutils literal notranslate"><span class="pre">EnvironmentContext.config</span></code></a> attribute.</p> <div class="admonition seealso"> <p class="admonition-title">See also</p> <p><a class="reference internal" href="runtime.html#alembic.runtime.environment.EnvironmentContext.get_x_argument" title="alembic.runtime.environment.EnvironmentContext.get_x_argument"><code class="xref py py-meth docutils literal notranslate"><span class="pre">EnvironmentContext.get_x_argument()</span></code></a></p> </div> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="alembic.config.Config.config_file_name"> <span class="sig-name descname"><span class="pre">config_file_name</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="pre">Optional</span><span class="p"><span class="pre">[</span></span><span class="pre">str</span><span class="p"><span class="pre">]</span></span></em><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">None</span></em><a class="headerlink" href="#alembic.config.Config.config_file_name" title="Permalink to this definition">¶</a></dt> <dd><p>Filesystem path to the .ini file in use.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="alembic.config.Config.config_ini_section"> <span class="sig-name descname"><span class="pre">config_ini_section</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="pre">str</span></em><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">None</span></em><a class="headerlink" href="#alembic.config.Config.config_ini_section" title="Permalink to this definition">¶</a></dt> <dd><p>Name of the config file section to read basic configuration from. Defaults to <code class="docutils literal notranslate"><span class="pre">alembic</span></code>, that is the <code class="docutils literal notranslate"><span class="pre">[alembic]</span></code> section of the .ini file. This value is modified using the <code class="docutils literal notranslate"><span class="pre">-n/--name</span></code> option to the Alembic runner.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="alembic.config.Config.file_config"> <span class="sig-name descname"><span class="pre">file_config</span></span><a class="headerlink" href="#alembic.config.Config.file_config" title="Permalink to this definition">¶</a></dt> <dd><p>Return the underlying <code class="docutils literal notranslate"><span class="pre">ConfigParser</span></code> object.</p> <p>Direct access to the .ini file is available here, though the <a class="reference internal" href="#alembic.config.Config.get_section" title="alembic.config.Config.get_section"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Config.get_section()</span></code></a> and <a class="reference internal" href="#alembic.config.Config.get_main_option" title="alembic.config.Config.get_main_option"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Config.get_main_option()</span></code></a> methods provide a possibly simpler interface.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="alembic.config.Config.get_main_option"> <span class="sig-name descname"><span class="pre">get_main_option</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">default</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><span class="pre">str</span></span></span><a class="headerlink" href="#alembic.config.Config.get_main_option" title="Permalink to this definition">¶</a></dt> <dt class="sig sig-object py"> <span class="sig-name descname"><span class="pre">get_main_option</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">default</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">Optional</span><span class="p"><span class="pre">[</span></span><span class="pre">str</span><span class="p"><span class="pre">]</span></span></span><span class="w"> </span><span class="o"><span class="pre">=</span></span><span class="w"> </span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><span class="pre">Optional</span><span class="p"><span class="pre">[</span></span><span class="pre">str</span><span class="p"><span class="pre">]</span></span></span></span></dt> <dd><p>Return an option from the ‘main’ section of the .ini file.</p> <p>This defaults to being a key from the <code class="docutils literal notranslate"><span class="pre">[alembic]</span></code> section, unless the <code class="docutils literal notranslate"><span class="pre">-n/--name</span></code> flag were used to indicate a different section.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="alembic.config.Config.get_section"> <span class="sig-name descname"><span class="pre">get_section</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">default</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">Dict</span><span class="p"><span class="pre">[</span></span><span class="pre">str</span><span class="p"><span class="pre">,</span></span><span class="w"> </span><span class="pre">str</span><span class="p"><span class="pre">]</span></span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><span class="pre">Dict</span><span class="p"><span class="pre">[</span></span><span class="pre">str</span><span class="p"><span class="pre">,</span></span><span class="w"> </span><span class="pre">str</span><span class="p"><span class="pre">]</span></span></span></span><a class="headerlink" href="#alembic.config.Config.get_section" title="Permalink to this definition">¶</a></dt> <dt class="sig sig-object py"> <span class="sig-name descname"><span class="pre">get_section</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">default</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">Optional</span><span class="p"><span class="pre">[</span></span><span class="pre">Dict</span><span class="p"><span class="pre">[</span></span><span class="pre">str</span><span class="p"><span class="pre">,</span></span><span class="w"> </span><span class="pre">str</span><span class="p"><span class="pre">]</span></span><span class="p"><span class="pre">]</span></span></span><span class="w"> </span><span class="o"><span class="pre">=</span></span><span class="w"> </span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><span class="pre">Optional</span><span class="p"><span class="pre">[</span></span><span class="pre">Dict</span><span class="p"><span class="pre">[</span></span><span class="pre">str</span><span class="p"><span class="pre">,</span></span><span class="w"> </span><span class="pre">str</span><span class="p"><span class="pre">]</span></span><span class="p"><span class="pre">]</span></span></span></span></dt> <dd><p>Return all the configuration options from a given .ini file section as a dictionary.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="alembic.config.Config.get_section_option"> <span class="sig-name descname"><span class="pre">get_section_option</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">section</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">name</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">default</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">Optional</span><span class="p"><span class="pre">[</span></span><span class="pre">str</span><span class="p"><span class="pre">]</span></span></span><span class="w"> </span><span class="o"><span class="pre">=</span></span><span class="w"> </span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><span class="pre">Optional</span><span class="p"><span class="pre">[</span></span><span class="pre">str</span><span class="p"><span class="pre">]</span></span></span></span><a class="headerlink" href="#alembic.config.Config.get_section_option" title="Permalink to this definition">¶</a></dt> <dd><p>Return an option from the given section of the .ini file.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="alembic.config.Config.get_template_directory"> <span class="sig-name descname"><span class="pre">get_template_directory</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><span class="pre">str</span></span></span><a class="headerlink" href="#alembic.config.Config.get_template_directory" title="Permalink to this definition">¶</a></dt> <dd><p>Return the directory where Alembic setup templates are found.</p> <p>This method is used by the alembic <code class="docutils literal notranslate"><span class="pre">init</span></code> and <code class="docutils literal notranslate"><span class="pre">list_templates</span></code> commands.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="alembic.config.Config.print_stdout"> <span class="sig-name descname"><span class="pre">print_stdout</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">text</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">arg</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><span class="pre">None</span></span></span><a class="headerlink" href="#alembic.config.Config.print_stdout" title="Permalink to this definition">¶</a></dt> <dd><p>Render a message to standard out.</p> <p>When <a class="reference internal" href="#alembic.config.Config.print_stdout" title="alembic.config.Config.print_stdout"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Config.print_stdout()</span></code></a> is called with additional args those arguments will formatted against the provided text, otherwise we simply output the provided text verbatim.</p> <p>e.g.:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">config</span><span class="o">.</span><span class="n">print_stdout</span><span class="p">(</span><span class="s1">'Some text </span><span class="si">%s</span><span class="s1">'</span><span class="p">,</span> <span class="s1">'arg'</span><span class="p">)</span> <span class="go">Some Text arg</span> </pre></div> </div> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="alembic.config.Config.set_main_option"> <span class="sig-name descname"><span class="pre">set_main_option</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">value</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><span class="pre">None</span></span></span><a class="headerlink" href="#alembic.config.Config.set_main_option" title="Permalink to this definition">¶</a></dt> <dd><p>Set an option programmatically within the ‘main’ section.</p> <p>This overrides whatever was in the .ini file.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters</dt> <dd class="field-odd"><ul class="simple"> <li><p><span class="target" id="alembic.config.Config.set_main_option.params.name"></span><strong>name</strong><a class="paramlink headerlink reference internal" href="#alembic.config.Config.set_main_option.params.name">¶</a> – name of the value</p></li> <li><p><span class="target" id="alembic.config.Config.set_main_option.params.value"></span><strong>value</strong><a class="paramlink headerlink reference internal" href="#alembic.config.Config.set_main_option.params.value">¶</a> – the value. Note that this value is passed to <code class="docutils literal notranslate"><span class="pre">ConfigParser.set</span></code>, which supports variable interpolation using pyformat (e.g. <code class="docutils literal notranslate"><span class="pre">%(some_value)s</span></code>). A raw percent sign not part of an interpolation symbol must therefore be escaped, e.g. <code class="docutils literal notranslate"><span class="pre">%%</span></code>. The given value may refer to another value already in the file using the interpolation format.</p></li> </ul> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="alembic.config.Config.set_section_option"> <span class="sig-name descname"><span class="pre">set_section_option</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">section</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">name</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">value</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><span class="pre">None</span></span></span><a class="headerlink" href="#alembic.config.Config.set_section_option" title="Permalink to this definition">¶</a></dt> <dd><p>Set an option programmatically within the given section.</p> <p>The section is created if it doesn’t exist already. The value here will override whatever was in the .ini file.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters</dt> <dd class="field-odd"><ul class="simple"> <li><p><span class="target" id="alembic.config.Config.set_section_option.params.section"></span><strong>section</strong><a class="paramlink headerlink reference internal" href="#alembic.config.Config.set_section_option.params.section">¶</a> – name of the section</p></li> <li><p><span class="target" id="alembic.config.Config.set_section_option.params.name"></span><strong>name</strong><a class="paramlink headerlink reference internal" href="#alembic.config.Config.set_section_option.params.name">¶</a> – name of the value</p></li> <li><p><span class="target" id="alembic.config.Config.set_section_option.params.value"></span><strong>value</strong><a class="paramlink headerlink reference internal" href="#alembic.config.Config.set_section_option.params.value">¶</a> – the value. Note that this value is passed to <code class="docutils literal notranslate"><span class="pre">ConfigParser.set</span></code>, which supports variable interpolation using pyformat (e.g. <code class="docutils literal notranslate"><span class="pre">%(some_value)s</span></code>). A raw percent sign not part of an interpolation symbol must therefore be escaped, e.g. <code class="docutils literal notranslate"><span class="pre">%%</span></code>. The given value may refer to another value already in the file using the interpolation format.</p></li> </ul> </dd> </dl> </dd></dl> </dd></dl> <dl class="py function"> <dt class="sig sig-object py" id="alembic.config.main"> <span class="sig-prename descclassname"><span class="pre">alembic.config.</span></span><span class="sig-name descname"><span class="pre">main</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">argv</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">prog</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.config.main" title="Permalink to this definition">¶</a></dt> <dd><p>The console runner function for Alembic.</p> </dd></dl> </section> <div class="clearer"></div> </div> </div> </div> <div class="sphinxsidebar" role="navigation" aria-label="main navigation"> <div class="sphinxsidebarwrapper"> <div id="searchbox" style="display: none" role="search"> <h3 id="searchlabel">Quick search</h3> <div class="searchformwrapper"> <form class="search" action="../search.html" method="get"> <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/> <input type="submit" value="Go" /> </form> </div> </div> <script>$('#searchbox').show(0);</script> <div> <h4>Previous topic</h4> <p class="topless"><a href="runtime.html" title="previous chapter">Runtime Objects</a></p> </div> <div> <h4>Next topic</h4> <p class="topless"><a href="commands.html" title="next chapter">Commands</a></p> </div> </div> </div> <div class="clearer"></div> </div> <div class="related" role="navigation" aria-label="related navigation"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="General Index" >index</a></li> <li class="right" > <a href="../py-modindex.html" title="Python Module Index" >modules</a> |</li> <li class="right" > <a href="commands.html" title="Commands" >next</a> |</li> <li class="right" > <a href="runtime.html" title="Runtime Objects" >previous</a> |</li> <li class="nav-item nav-item-0"><a href="../index.html">Alembic 1.8.1 documentation</a> »</li> <li class="nav-item nav-item-1"><a href="index.html" >API Details</a> »</li> <li class="nav-item nav-item-this"><a href="">Configuration</a></li> </ul> </div> <div class="footer" role="contentinfo"> © Copyright 2010-2022, Mike Bayer. Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 4.5.0. </div> </body> </html>