psycodict 1.0.0rc1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
psycodict/__init__.py ADDED
@@ -0,0 +1,54 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ This module provides an interface to Postgres supporting
4
+ the kinds of queries needed by the LMFDB.
5
+
6
+ The examples in this package's docstrings are real transcripts, run as
7
+ doctests by ``tests/test_doctests.py`` against two small tables of LMFDB
8
+ data that it creates: ``test_fields`` (22 selected number fields of
9
+ degree at most 3) and ``test_curves`` (a dozen elliptic curves over three
10
+ of those fields).
11
+
12
+ EXAMPLES::
13
+
14
+ >>> from psycodict.database import PostgresDatabase
15
+ >>> db = PostgresDatabase() # configuration found via $PSYCODICT_CONFIG / config.ini
16
+ >>> db
17
+ Interface to Postgres database
18
+ >>> 'test_fields' in db.tablenames
19
+ True
20
+ >>> nf = db.test_fields
21
+ >>> nf
22
+ Interface to Postgres table test_fields
23
+
24
+ You can search using the methods ``search``, ``lucky`` and ``lookup``::
25
+
26
+ >>> nf.lookup('2.0.23.1', 'class_number')
27
+ 3
28
+ >>> nf.lucky({'degree': 2, 'disc_sign': 1, 'disc_abs': 5}, projection=0)
29
+ '2.2.5.1'
30
+ >>> list(nf.search({'ramps': {'$contains': [2]}}, projection=0))
31
+ ['2.0.4.1', '2.0.8.1', '2.2.8.1', '2.2.12.1', '3.1.44.1', '3.1.76.1']
32
+ """
33
+
34
+ # Single source of truth for the package version: pyproject.toml reads it via
35
+ # ``[tool.setuptools.dynamic]``, and it works from an uninstalled checkout too.
36
+ __version__ = "1.0.0rc1"
37
+
38
+ try:
39
+ import psycopg
40
+ assert psycopg
41
+ except ImportError:
42
+ print('Missing psycopg dependency; either do "pip install psycopg[binary]" or "pip install psycopg" (requires libpq installed on your system)')
43
+ raise
44
+
45
+ from .utils import DelayCommit
46
+
47
+ assert DelayCommit
48
+ # Re-export the SQL composition classes of the driver psycodict is built on.
49
+ # Downstream projects that compose queries for _execute should import these
50
+ # from psycodict rather than from a driver directly, so that their code does
51
+ # not depend on which driver psycodict uses.
52
+ from psycopg.sql import SQL, Identifier, Placeholder, Literal, Composable, Composed
53
+
54
+ assert SQL and Identifier and Placeholder and Literal and Composable and Composed