Is there a python binding to the Berkeley DB XML database? [closed] - python

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 2 months ago.
Improve this question
I'm trying to migrate some perl code to python and it uses Sleeypcat::DbXml 'simple' to get read access to a .dbxml file, creates a XmlManager, calls createQueryContext, openContainer and query to get an XmlValue. I have found https://pypi.org/project/berkeleydb/ to support the Berkeley DB in general, but it has no mention of this XML layer. Is there an existing API I can use in python 3?

Berkeley dbxml does come with a Pyhon bindings. I ended up having to make modifications to the SWIG interface files to get it to run with Python3. If you are interested in building for a recent Python, you will need to make some modifications to the Python interface file. Specifically, you have to
redefine PYSTR_* macros to use unicode strings
make changes to the initialization code to return the module
update the Python 3 iterator code to use __next__ via a %rename pragma
potentially add code for missing objects an changed interfaces, e.g. I added an XmlResultsIterator, and added som code to XmlManager to let me reindex containers.
You then need to regenerate the swig interface and recompile the module. I don't know StackOverflow's policy on posting patches, but if it's allowed I'd be happy to post the patches that I created for dbxml 6.1.4 and Python 3.9 for you. Getting it all compiled is a little bit of work, but very doable.

Berkeley DB and Berkeley DB XML are two different products. My python bindings (legacy "bsddb3" and current "berkeleydb") only interface with Berkeley DB.
I am not aware of any Python bindings for Berkeley DB XML.
I am a freelance with commercial contracts, if that option would be useful to you.

Related

using Python to process and generate Excel files [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
Wondering if Python has free and reliable library to read Excel file, manipulate data and generate Excel file output, just like VBA did? My current problem is, the project has both Python and VBA code, I am trying to see if I can use single programming language to make it simple. Thanks.
Using Python 2.7.
regards,
Lin
I either use openpyxl or the pywin32 COM interface directly.
openpyxl is very fast as it manipulates data directly in the excel file on disk, where as the pywin32 com interface uses Excel itself, with the python code mimicking what VBA does.
The main difference between the two is that openpxl only gives you a subset of commands, so great for pulling data out of an excel file to use elsewhere or building a new excel file from existing data. However to get the full functionality you need to use the COM interface.
This site gives a good intro to using the COM interface. One thing to watch out for is the constants that are scattered throughout the COM interface calls. You generally need to find out those values yourself, you can start by looking here
Finally you can also take a look at IronPython which is a .NET implementation of python which gives a cleaner interface but isn't actually vanilla python (and not cross-platform), so maybe not what you want.
I would like to recommend openpyxl
I used it for creating basic Excel reports for business teams, and it has been a pleasure to use. :-)

Fast relational database for simple use with Python [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
For my link scraping program (written in python3.3) I want to use a database to store around 100.000 websites:
just the URL,
a time stamp
and for each website a list of several properties
I don't have knowledge about databases, but found the following may fit my purpose:
Postgresql
SQLite
Firebird
I'm interested in speed (to access the database and to get the wanted information). For example: for website x does property y exist and if yes read it. The speed of writing is of course also important.
My question: Are there big differences in speed or does it not matter for my small program? Maybe someone can tell which database fits my requirements (and is easy to handle with Python).
The size and scale of your database is not particularly large, and it's well within the scope of almost any off-the-shelf database solution.
Basically, what you're going to do is install the database server on your machine and it will come up on a given port. You then can install a library in Python to access it.
For example, if you want to use Postgresql, you'll install it on your machine and it will come up attached to some port like 5000, or port 5432.
But if you just have the information you're talking about to store and retrieve, you probably want to go with a NoSQL solution because it's very easy.
For example, you can install mongodb on your server, then install pymongo. The tutorial for pymongo will teach you pretty much everything you need for your application.
If speed is the main criteria, then i would suggest to go with a in-memory database.
Take a look at http://docs.python.org/2/library/sqlite3.html
it can be used as a normal database too, for the in-memory mode use the below and the db should get created in the RAM itself and hence much faster run-time access.
import sqlite3
conn = sqlite3.connect(':memory:')

Testing REST API [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
Improve this question
I am developing a REST API on Django. What do other uses to craft json msgs to test? Is there a browser plugin, python lib, curl, something else?
If you want to write Python try using the Requests library to do some basic testing from the client side. There is a CLI tool based on this called httpie that you might also want to check out. You can also use curl for testing if you prefer the command line but it is probably easier to use Requests in the long run from Python code if you are dealing with a more complex API or want to do anything repeatedly.
The Python 2.6+ standard library includes the json module which should help you create some JSON objects to do testing.
Here is a link to the documentation: http://docs.python.org/library/json.html
JSON is simple because you have a choice of JSON libraries to use in Python. Before you choose, read this article http://deron.meranda.us/python/comparing_json_modules/ because I suspect that you will find it very useful to use a strict parser for your testing. The benchmarks may be outdated, but the strict validating parsers are unlikely to have been superceded.
Write some Python code that acts as a web client, using a library like httplib2 to access your app. If your like a lot of people and all of your JSON is a single Javascript object, then you could keep your test data in any old database such as SQLite, read it into a Python dict, and encode it into a JSON object with one function call. Then for the actual test, after you receive a JSON reply, decode it into a dict and you have a normal Python object to use for comparisons.

Python test "framework" for testing input files and their outputs [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
I'm writing end-to-end tests for my tool, which is written in Python. The tool reads a file as input. I want to test its exit code, and its output.
This is a fairly common idiom, and I've seen it done in several ways. In the PHP project, each test is a file, and has lines like: INPUT:, EXPECTED:, EXPECTED_REGEX:, etc. In my own phc project, each file is a normal source file, but with a comment added to the top, which includes keywords like EXPECTED. I think I had copied that off gcc which uses a much more complex tool written in tcl.
Are there frameworks, libraries, etc, that do this in Python? It should:
read the source file
parse special keywords (or similar) corresponding to expected output, exit code, words/regexes it expects to find or not find,
check that the output is correct.
While it doesn't seem hard in theory, I recall lots of edge-cases (esp involving escaping) when implementing this before, and would rather not reinvent the wheel.
The robot framework might be helpful. It is a keyword driven functional testing tool implemented in python and can be extended with pythion or java.
see: http://robotframework.googlecode.com/svn/tags/robotframework-2.5.4/doc/userguide/RobotFrameworkUserGuide.html
There are a number of built in libraries that you might be able to apply to solve your problem, including a OperatingSystem library for working with files etc. and a Strings library for working with strings:
http://robotframework.googlecode.com/svn/tags/robotframework-2.5.4/doc/userguide/RobotFrameworkUserGuide.html#standard-libraries
There is also a http://pythonpaste.org/scripttest/ library by Ian Bicking.
Since the implementation of file io is system dependent, why not mock out the file reading and writing using StringIO:
http://docs.python.org/library/stringio.html
and then test the bulk of the logic (reading from a file, doing some stuff, writing to a file) in python?
Then, perhaps you could have one end to end test for basic sanity by having a separate python file call out to the script using the commands module or something similar where you are calling out to it as another process:
http://docs.python.org/library/commands.html
Using that you could get both the output, and the status.

Embedded Linux device tree parser in python? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 2 years ago.
Improve this question
I am looking to create a utility that validates Embedded (PPC or ARM) Linux *.dts (device tree source) or *.dtb (binary) files against an XML configuration file from another tool. So, I need to parse the dts or dtb files. I would really like to do this with Python. Does anyone know of a Python library or tool out there that parses dts or dtb files? A Python implementation of the device tree compiler (dtc) would be perfect, but I've not seen one yet.
It seems that the Zephyr project (a RTOS making use device trees) comes with a rather generic Python module dtlib to parse device tree source files. The module is part of the Zephyr source tree and stored in scripts/dts/dtlib.py.
Update December 2021
It seems that this got separated into its own repository available at https://github.com/zephyrproject-rtos/python-devicetree.
There is no python binding for libfdt (the device tree manipulation library shipped with dtc) yet, but it should be fairly straightforward to create one.
If you're interested in doing this, the Python docs have a bit about extending python using c modules: http://docs.python.org/release/2.6/extending/extending.html . The swig utility can be used to automatically create the Python-to-C interface, so you just end up writing a small swig configuration file.
If you do end up doing this, send the folks at devicetree-discuss#lists.ozlabs.org an email - we'd be keen to hear how you go!
libfdt is used to parse dtb file instead of device tree file (dts/dtsi), so it might not help to read libfdt, and you can't simply use SWIG to create a python binding of existing device parser.
Since dtc uses lex/yacc as the parsing tool and its syntax definition is available in kernel, I suggest you could use lex/yacc in python ([PLY]:http://www.dabeaz.com/ply/) to compose your own device tree parser.

Categories