[](https://circleci.com/gh/yohanboniface/psycopg-postgis) [](https://pypi.python.org/pypi/psycopg-postgis) [](https://pypi.python.org/pypi/psycopg-postgis) [](https://pypi.python.org/pypi/psycopg-postgis) [](https://pypi.python.org/pypi/psycopg-postgis)
# python-postgis
PostGIS helpers for psycopg2 and asyncpg.
## Install
pip install postgis
If you want a compiled version, first install `cython`:
pip install cython
pip install postgis
## Usage
You need to register the extension:
# With psycopg2
> from postgis.psycopg import register
> register(connection)
# With asyncpg
> from postgis.asyncpg import register
> await register(connection)
Then you can pass python geometries instance to psycopg:
> cursor.execute('INSERT INTO table (geom) VALUES (%s)', [Point(x=1, y=2, srid=4326)])
And retrieve data as python geometries instances:
> cursor.execute('SELECT geom FROM points LIMIT 1')
> geom = cursor.fetchone()[0]
> geom
<Point POINT(1.0 2.0)>
## Example with psycopg2
> import psycopg2
> from postgis import LineString
> from postgis.psycopg import register
> db = psycopg2.connect(dbname="test")
> register(db)
> cursor.execute('CREATE TABLE IF NOT EXISTS mytable ("geom" geometry(LineString) NOT NULL)')
> cursor.execute('INSERT INTO mytable (geom) VALUES (%s)', [LineString([(1, 2), (3, 4)], srid=4326)])
> cursor.execute('SELECT geom FROM mytable LIMIT 1')
> geom = cursor.fetchone()[0]
> geom
<LineString LINESTRING(1.0 2.0, 3.0 4.0)>
> geom[0]
<Point POINT(1.0 2.0)>
> geom.coords
((1.0, 2.0), (3.0, 4.0))
> geom.geojson
{'coordinates': ((1.0, 2.0), (3.0, 4.0)), 'type': 'LineString'}
> str(geom.geojson)
'{"type": "LineString", "coordinates": [[1, 2], [3, 4]]}'
## Example with asyncpg
from postgis.asyncpg import register
pool = await create_pool(**DB_CONFIG, loop=loop, max_size=100,
init=register)
# python-postgis
PostGIS helpers for psycopg2 and asyncpg.
## Install
pip install postgis
If you want a compiled version, first install `cython`:
pip install cython
pip install postgis
## Usage
You need to register the extension:
# With psycopg2
> from postgis.psycopg import register
> register(connection)
# With asyncpg
> from postgis.asyncpg import register
> await register(connection)
Then you can pass python geometries instance to psycopg:
> cursor.execute('INSERT INTO table (geom) VALUES (%s)', [Point(x=1, y=2, srid=4326)])
And retrieve data as python geometries instances:
> cursor.execute('SELECT geom FROM points LIMIT 1')
> geom = cursor.fetchone()[0]
> geom
<Point POINT(1.0 2.0)>
## Example with psycopg2
> import psycopg2
> from postgis import LineString
> from postgis.psycopg import register
> db = psycopg2.connect(dbname="test")
> register(db)
> cursor.execute('CREATE TABLE IF NOT EXISTS mytable ("geom" geometry(LineString) NOT NULL)')
> cursor.execute('INSERT INTO mytable (geom) VALUES (%s)', [LineString([(1, 2), (3, 4)], srid=4326)])
> cursor.execute('SELECT geom FROM mytable LIMIT 1')
> geom = cursor.fetchone()[0]
> geom
<LineString LINESTRING(1.0 2.0, 3.0 4.0)>
> geom[0]
<Point POINT(1.0 2.0)>
> geom.coords
((1.0, 2.0), (3.0, 4.0))
> geom.geojson
{'coordinates': ((1.0, 2.0), (3.0, 4.0)), 'type': 'LineString'}
> str(geom.geojson)
'{"type": "LineString", "coordinates": [[1, 2], [3, 4]]}'
## Example with asyncpg
from postgis.asyncpg import register
pool = await create_pool(**DB_CONFIG, loop=loop, max_size=100,
init=register)
Release files for postgis 1.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| postgis-1.0.4.tar.gz | 52.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| postgis-1.0.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 115.7 kB
Release files / postgis-1.0.4.tar.gz
| Download URL | postgis-1.0.4.tar.gz |
|---|---|
| Size | 52.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3d41f087e249a2a8b6720931e6f8f22b7747801f250265a8b8ac5f9d48221e63
|
|
BLAKE2b-256 checksum How to use checksums |
93096edfb7bda8b6645de68c232709aaf11ac2a945ced37ebb69e513d9dc01e5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / postgis-1.0.4-py3-none-any.whl
| Download URL | postgis-1.0.4-py3-none-any.whl |
|---|---|
| Size | 63.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1dfa62d33c585d68a54bdd47c21bdcb9302f9cbb0ef5aec360e64d2c3e0e1a93
|
|
BLAKE2b-256 checksum How to use checksums |
fee1522b5e0f9c0edf8bf864ce80a060d7c3a87d88070bfb2640a70eb0b006b0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |