File: types.rst

package info (click to toggle)
django-environ 0.12.0-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 516 kB
  • sloc: python: 2,434; makefile: 171
file content (182 lines) | stat: -rw-r--r-- 5,567 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
===============
Supported types
===============

The following are all type-casting methods of :py:class:`.environ.Env`.

* :py:meth:`~.environ.Env.str`
* :py:meth:`~.environ.Env.bool`
* :py:meth:`~.environ.Env.int`
* :py:meth:`~.environ.Env.float`
* :py:meth:`~.environ.Env.json`
* :py:meth:`~.environ.Env.url`
* :py:meth:`~.environ.Env.list`: (accepts values like ``(FOO=a,b,c)``)
* :py:meth:`~.environ.Env.tuple`:  (accepts values like ``(FOO=(a,b,c))``)
* :py:meth:`~.environ.Env.path`:  (accepts values like ``(environ.Path)``)
* :py:meth:`~.environ.Env.dict`:   (see below, ":ref:`environ-env-dict`" section)
* :py:meth:`~.environ.Env.db_url` (see below, ":ref:`environ-env-db-url`" section)
* :py:meth:`~.environ.Env.cache_url` (see below, ":ref:`environ-env-cache-url`" section)
* :py:meth:`~.environ.Env.search_url` (see below, ":ref:`environ-env-search-url`" section)
* :py:meth:`~.environ.Env.email_url` (see below, ":ref:`environ-env-email-url`" section)


.. _environ-env-dict:

``environ.Env.dict``
======================

:py:class:`.environ.Env` may parse complex variables like with the complex type-casting.
For example:

.. code-block:: python

   import environ


   env = environ.Env()

   # {'key': 'val', 'foo': 'bar'}
   env.parse_value('key=val,foo=bar', dict)

   # {'key': 'val', 'foo': 1.1, 'baz': True}
   env.parse_value(
       'key=val;foo=1.1;baz=True',
       dict(value=str, cast=dict(foo=float,baz=bool))
  )

For more detailed example see ":ref:`complex_dict_format`".


.. _environ-env-db-url:

``environ.Env.db_url``
======================

:py:meth:`~.environ.Env.db_url` supports the following URL schemas:

.. glossary::

    Amazon Redshift
      **Database Backend:** ``django_redshift_backend``

      **URL schema:** ``redshift://``

    LDAP
      **Database Backend:** ``ldapdb.backends.ldap``

      **URL schema:** ``ldap://host:port/dn?attrs?scope?filter?exts``

    MSSQL
      **Database Backend:** ``sql_server.pyodbc``

      **URL schema:** ``mssql://user:password@host:port/dbname``

      With MySQL you can use the following schemas: ``mysql``, ``mysql2``.

    MySQL (GIS)
      **Database Backend:** ``django.contrib.gis.db.backends.mysql``

      **URL schema:** ``mysqlgis://user:password@host:port/dbname``

    MySQL
      **Database Backend:** ``django.db.backends.mysql``

      **URL schema:** ``mysql://user:password@host:port/dbname``

    MySQL Connector Python from Oracle
      **Database Backend:** ``mysql.connector.django``

      **URL schema:** ``mysql-connector://``

    Oracle
      **Database Backend:** ``django.db.backends.oracle``

      **URL schema:** ``oracle://user:password@host:port/dbname``

    PostgreSQL
      **Database Backend:** ``django.db.backends.postgresql``

      **URL schema:** ``postgres://user:password@host:port/dbname``

      With PostgreSQL you can use the following schemas: ``postgres``, ``postgresql``, ``psql``, ``pgsql``, ``postgis``.
      You can also use UNIX domain sockets path instead of hostname. For example: ``postgres://path/dbname``.
      The ``django.db.backends.postgresql_psycopg2`` will be used if the Django version is less than ``2.0``.

    PostGIS
      **Database Backend:** ``django.contrib.gis.db.backends.postgis``

      **URL schema:** ``postgis://user:password@host:port/dbname``

    PyODBC
      **Database Backend:** ``sql_server.pyodbc``

      **URL schema:** ``pyodbc://``

    SQLite
      **Database Backend:** ``django.db.backends.sqlite3``

      **URL schema:** ``sqlite:////absolute/path/to/db/file``

      SQLite connects to file based databases. URL schemas ``sqlite://`` or
      ``sqlite://:memory:`` means the database is in the memory (not a file on disk).

    SpatiaLite
      **Database Backend:** ``django.contrib.gis.db.backends.spatialite``

      **URL schema:** ``spatialite:///PATH``

      SQLite connects to file based databases. URL schemas ``sqlite://`` or
      ``sqlite://:memory:`` means the database is in the memory (not a file on disk).


.. _environ-env-cache-url:

``environ.Env.cache_url``
=========================

:py:meth:`~.environ.Env.cache_url` supports the following URL schemas:

* Database: ``dbcache://``
* Dummy: ``dummycache://``
* File: ``filecache://``
* Memory: ``locmemcache://``
* Memcached:

  * ``memcache://`` (uses ``python-memcached`` backend, deprecated in Django 3.2)
  * ``pymemcache://`` (uses ``pymemcache`` backend if Django >=3.2 and package is installed, otherwise will use ``pylibmc`` backend to keep config backwards compatibility)
  * ``pylibmc://``

* Redis: ``rediscache://``, ``redis://``, or ``rediss://``


.. _environ-env-search-url:

``environ.Env.search_url``
==========================

:py:meth:`~.environ.Env.search_url` supports the following URL schemas:

* Elasticsearch: ``elasticsearch://`` (http) or ``elasticsearchs://`` (https)
* Elasticsearch2: ``elasticsearch2://`` (http) or ``elasticsearch2s://`` (https)
* Elasticsearch5: ``elasticsearch5://`` (http) or ``elasticsearch5s://`` (https)
* Elasticsearch7: ``elasticsearch7://`` (http) or ``elasticsearch7s://`` (https)
* Solr: ``solr://``
* Whoosh: ``whoosh://``
* Xapian: ``xapian://``
* Simple cache: ``simple://``


.. _environ-env-email-url:

``environ.Env.email_url``
==========================

:py:meth:`~.environ.Env.email_url` supports the following URL schemas:

* SMTP: ``smtp://``
* SMTP+SSL: ``smtp+ssl://``
* SMTP+TLS: ``smtp+tls://``
* Console mail: ``consolemail://``
* File mail: ``filemail://``
* LocMem mail: ``memorymail://``
* Dummy mail: ``dummymail://``