Skip to main content

Speedups

https://github.com/wolph/speedups/actions/workflows/build_wheels.yml/badge.svg https://github.com/wolph/speedups/actions/workflows/tox.yml/badge.svg

This library contains a number of functions for speeding up critical parts of your Python code without having to bother with the hassle of building binary extensions. That way you can keep your main packages simple PEP517 based packages and still get the speedups.

Currently only a few functions are available, but several more are planned.

Generic endian conversion functions in speedups.hton:

  • void pack_int16(char *buf, int16_t x)

  • void pack_int32(char *buf, int32_t x)

  • void pack_int64(char *buf, int64_t x)

  • void pack_float(char *buf, float f)

  • void pack_double(char *buf, double f)

  • int16_t unpack_int16(const char *buf)

  • uint16_t unpack_uint16(const char *buf)

  • int32_t unpack_int32(const char *buf)

  • uint32_t unpack_uint32(const char *buf)

  • int64_t unpack_int64(const char *buf)

  • uint64_t unpack_uint64(const char *buf)

  • float unpack_float(const char *buf)

  • double unpack_double(const char *buf)

These functions are used to convert between native and network byte order and are meant to be used from Cython code. Examples can be found in the speedups.psycopg_array code.

For the psycopg library we have a binary COPY loader to convert a PostgreSQL array to a numpy ndarray. This can be used with the copy() method of a psycopg cursor: https://www.psycopg.org/psycopg3/docs/basic/copy.html

It supports the following PostgreSQL types:

  • float4 (numpy.float32)

  • float8 (numpy.float64)

  • smallint (numpy.int16)

  • integer (numpy.int32)

  • bigint (numpy.int64)

Additionally, it supports arrays varying from 1D to N-D so a 2D or 3D array are supported.

cursor: psycopg.Cursor
psycopg_loaders.NumpyLoader.install(cursor)

query = '''
COPY (
    SELECT array_agg(x)
    FROM generate_series(1, 100000) x
) TO STDOUT WITH BINARY
'''

copy: psycopg.Copy
with cursor.copy(query) as copy:
    copy.set_types(['integer[]'])

    for row in copy.rows():
        print(row)

Metadata

Release files for speedups 1.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for speedups 1.3.0
File Size Uploaded
speedups-1.3.0.tar.gz 176.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for speedups 1.3.0
File Interpreter ABI Platform
speedups-1.3.0-cp312-cp312-macosx_12_0_x86_64.whl CPython 3.12 CPython 3.12 macOS 12.0+ x86-64 Details

Total release size: 454.4 kB

Release files / speedups-1.3.0.tar.gz

Download URL speedups-1.3.0.tar.gz
Size 176.7 kB
Tags Source
SHA-256 checksum
How to use checksums
5f57fe5e8e92a62d7e23e24c6978f4928e5be7d1a37f1ae5f7b1c523dad580c7
BLAKE2b-256 checksum
How to use checksums
7cb7666223e770a9975bb43f0b0db1f7cf4f372d2ece7affe76d0c357f6c0556
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.2

Release files / speedups-1.3.0-cp312-cp312-macosx_12_0_x86_64.whl

Download URL speedups-1.3.0-cp312-cp312-macosx_12_0_x86_64.whl
Size 277.6 kB
Tags CPython 3.12 macOS 12.0+ x86-64
SHA-256 checksum
How to use checksums
9f074ad4acf04afdc58d0a4de393f8f06e206a5e5fd407c40673f50ccd519f72
BLAKE2b-256 checksum
How to use checksums
43eaf527a53b331a7334185d67689d994fd09962a173b88a5271b6c03d35efca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.2

Release history Release notifications | RSS feed

2.3.3

50 release files

2.3.2

50 release files

2.3.1

50 release files

2.3.0

50 release files

2.2.0

19 release files

2.1.0

19 release files

1.4.0

17 release files

1.3.2

16 release files

This release

1.3.0 This release

2 release files

1.2.0

17 release files

1.1.0

18 release files

1.0.0

17 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page