Python bindings for the pxlib library for reading and writing Paradox databases.
Project description
pypxlib
Python bindings for the pxlib library for reading and writing Paradox databases. The version of pxlib currently exposed by pypxlib is 0.6.5.
Usage
pypxlib exposes a high-level API for reading Paradox databases. To use this API, you need the following import:
from pypxlib import Table
Get the field names in a table:
>>> table = Table('data.db')
>>> table.fields
['field1', 'field2', 'field3']
Get the number of rows:
>>> len(table)
123
Get the first row:
>>> row = table[0]
>>> row
Row(field1='foo', field2=13, field3=True)
Access a row’s properties:
>>> row.field1
'foo'
>>> row['field1']
'foo'
Iterate over all rows:
>>> for row in table:
... print(row)
...
Row(field1='foo', field2=13, field3=True)
Row(field2='bar', field2=87, field3=True)
...
Don’t forget to close the table!
table = Table('data.db')
try:
# Process the table...
finally:
table.close()
Or use it as a context manager:
with Table('data.db') as table:
# Process the table...
Access to pxlib via ctypes
pypxlib is esentially a thin wrapper around the pxlib C library. The high-level API described above makes it easy to read tables. If you also need to write to a table, or another more complicated use case, then you can fall back to the ctypes bindings of pxlib exposed by this library:
from pypxlib.pxlib_ctypes import *
pxdoc = PX_new()
PX_open_file(pxdoc, b"test.db")
num_fields = PX_get_num_fields(pxdoc)
print('test.db has %d fields:' % num_fields)
for i in range(num_fields):
field = PX_get_field(pxdoc, i)
print(field.contents.px_fname)
# Close the file:
PX_close(pxdoc)
# Free the memory associated with pxdoc:
PX_delete(pxdoc)
All the PX_... functions come directly from the list of pxlibs functions. Note that you do not need to call PX_boot() and PX_shutdown, as these functions are already called when importing pypxlib, and via an atexit handler.
Dynamic libraries in this repository
Here is a list of dynamic libraries contained in this repository, and how they were obtained:
libpx.so, pxlib.dll, libpx.dylib were obtained from building pxlib 0.6.5 on Ubuntu 14.0.4.1, Windows 7 and Mac OS X 10.10.5, respectively. See Building pxlib below.
libiconv2.dll was downloaded as part of the Binaries zip file from http://gnuwin32.sourceforge.net/packages/libiconv.htm. Its version is 1.9.2-1.
Building pxlib
This project contains dynamic libraries for version 0.6.5 of the pxlib library. Here, the steps that were necessary to compile the library on the various operating systems are documented.
Ubuntu 14.04.1 LTS
sudo apt-get update
sudo apt-get install build-essential
wget 'http://downloads.sourceforge.net/project/pxlib/pxlib/0.6.5/pxlib-0.6.5.tar.gz?ts='`date +%s`'&use_mirror=freefr' -o pxlib-0.6.5.tar.gz
tar -zxvf pxlib-0.6.5.tar.gz
cd pxlib-0.6.5/
./configure
make
sudo make install
OS X 10.10.5
sudo brew install intltool
sudo brew link xy
sudo brew install gettext
curl -L 'http://downloads.sourceforge.net/project/pxlib/pxlib/0.6.5/pxlib-0.6.5.tar.gz?ts='`date +%s`'&use_mirror=freefr' -o pxlib-0.6.5.tar.gz
tar -zxvf pxlib-0.6.5.tar.gz
cd pxlib-0.6.5/
echo './configure --prefix=out' | brew sh
sed -i '' 's/#define HAVE_LOCALE_H 1//' config.h
make
make install
Windows 7
Download and install Visual Studio Community 2015.
Download and install CMake.
Download the pxlib 0.6.5 sources from http://sourceforge.net/projects/pxlib/files/latest/download?source=files.
Extract the pxlib sources to a directory, eg. C:\pxlib-0.6.5.
Download libiconv-1.9.2-1-lib.zip from http://sourceforge.net/projects/gnuwin32/files/libiconv/1.9.2-1/libiconv-1.9.2-1-lib.zip/download.
Extract libiconv-1.9.2-1-lib.zip into C:\pxlib-0.6.5.
Open C:\pxlib-0.6.5\CMakeLists.txt with a text editor and add the following line before check_include_file("iconv.h" ...): set(CMAKE_REQUIRED_INCLUDES ${CMAKE_SOURCE_DIR}/include).
Also add the line TARGET_LINK_LIBRARIES(pxlib ${CMAKE_SOURCE_DIR}/lib/libiconv.lib) to the end of the file.
Open a command prompt and cd to C:\pxlib-0.6.5.
Run cmake ..
Open the generated file C:\pxlib-0.6.5\ALL_BUILD.vcxproj in Visual Studio.
Under Build select Configuration Manager. Select Configuration Release for Project pxlib.
Click Build/Build Solution.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file pypxlib-1.0.tar.gz
.
File metadata
- Download URL: pypxlib-1.0.tar.gz
- Upload date:
- Size: 915.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a375eaef7bae75d52111da45150712bfb4588c431228df04471954f281c68991 |
|
MD5 | 070132def7f8f383e8fca49b33c4bedc |
|
BLAKE2b-256 | 8f2fe997a3231a5cd80204b1975a54fedacfc5e20b98605f89b9bd9169a93514 |