Python

1921 readers
1 users here now

A community for talking about the Python programming language.

founded 1 year ago
MODERATORS
1
2
 
 
3
4
 
 

Simple Python bindings for @ggerganov's llama.cpp library. This package provides:

Low-level access to C API via ctypes interface.
High-level Python API for text completion
    OpenAI-like API
    LangChain compatibility
    LlamaIndex compatibility
OpenAI compatible web server
    Local Copilot replacement
    Function Calling support
    Vision API support
    Multiple Models

Documentation is available at https://llama-cpp-python.readthedocs.io/en/latest.

5
6
7
8
 
 

cross-posted from: https://programming.dev/post/13395352

Would love to hear any suggestions, feedback or comments.

9
10
11
12
 
 

It runs!.. it's just a toy.

13
14
 
 

is there any win32 alternative that is multi platform and doesnt consume too much resources and are fast? thx

15
16
17
 
 

Had some fun with generators while practicing DRY.

18
 
 

Wondering if anyone here has some advise or a good place to learn about dealing with databases with Python. I know SQL fairly well for pulling data and simple updates, but running into potential performance issues the way I've been doing it. Here are 2 examples.

  1. Dealing with Pandas dataframes. I'm doing some reconciliation between a couple of different datasources. I do not have a primary key to work with. I have some very specific matching criteria to determine a match. The matching process is all built within Python. Is there a good way to do the database commits with updates/inserts en masse vs. line by line? I've looked into upsert (or inserts with clause to update with existing data), but pretty much all examples I've seen rely on primary keys (which I don't have since the data has 4 columns I'm matching on).

  2. Dealing with JSON files which have multiple layers of related data. My database is built in such a way that I have a table for header information, line level detail, then third level with specific references assigned to the line level detail. As with a lot of transactional type databases there can be multiple references per line, multiple lines per header. I'm currently looping through the JSON file starting with the header information to create the primary key, then going to the line level detail to create a primary key for the line, but also include the foreign key for the header and also with the reference data. Before inserting I'm doing a lookup to see if the data already exists and then updating if it does or inserting a new record if it doesn't. This works fine, but is slow taking several seconds for maybe 100 inserts in total. While not a big deal since it's for a low volume of sales. I'd rather learn best practice and do this properly with commits/transactions vs inserting an updating each record individually within the ability to rollback should an error occur.

19
 
 

So I made a small little command-line utility for myself just for practice, but I had a hard time figuring out how to actually turn it into something I can just use on the command line with no fuss. It uses a virtual environment as Python packages should, so it needs to be run in that environment and I was having trouble figuring out how to do it.

But then I remembered that pipx runs application in a virtual environment, and after checking the docs, I found out that it allows installing local packages by just pointing install at the package directory. So I did, and after setting up the command name as a project script that points to main it ended up working.

I haven't ever heard of anyone doing something like this for a personal program though. Is something like this a bad idea? Is it over engineering or error prone? Is there another way that most people do something like this?

20
 
 

cross-posted from: https://programming.dev/post/21515

Some surprising, but valid, python syntax examples.

21
 
 

I learned a little bit of python back in college with the hope that it would give me a competitive edge in the field I hoped to enter. Lo and behold, I got a job in a different industry entirely and any knowledge of coding I once had became irrelevant.

Would it be worth it to pick up my python textbook again and self-teach in my free time if I don't want to make a career of coding? What exactly can python be used to create?

22
 
 

With r/python out for the next 48 hours, here’s a post to promote continuing discussion a language we all love. Python.

23
 
 

I was playing a bit with the nogil version of Python 3.12. In theory it should have large gains for multi threaded workloads (at the expense of single threaded workloads).

Has anyone given it a try?

https://github.com/colesbury/nogil-3.12