more than one python file im a resulting shared library

4 views
Skip to first unread message

wintermute _ki

unread,
Jan 8, 2026, 8:02:05 AM (6 days ago) Jan 8
to cython-users
Hi together,

I have the following problem. The base for my small project is the directory structure as shown :

projekt_root/
 ├── setup.py
 └── commons/
     ├── __init__.py
     ├── singleton.py  
     └── logger.py

The source code for the singleton.py and logger.py :

# commons/singleton.py
class CSingleton(object):

    instances = {}

    def __new__(clazz, *args, **kwargs):
        if clazz not in clazz.instances:
            clazz.instances[clazz] = super(CSingleton, clazz).__new__(clazz)
        return clazz.instances[clazz]


# commons/logger.py
from logging import Logger, Formatter, INFO
from logging.handlers import RotatingFileHandler
from commons.singleton import CSingleton

class CLogger(CSingleton, Logger):

    initialized = False

    def __init__(self, log_format="%(asctime)s - %(levelname)s - %(funcName)s - %(message)s"):
        if not self.initialized:
            Logger.__init__(self, name="LeosDesk", level=INFO)
            self.log_file = "resources/logfile.txt"
            self.formatter = Formatter(log_format)

            fileHandler = RotatingFileHandler(self.log_file)
            fileHandler.setFormatter(self.formatter)
            self.addHandler(fileHandler)

            self.initialized = True

What steps do I need to take to compile both source files into a single shared library?
In my production environment, I only want to have the shared library and all the necessary init
files. No source code from singleton.py and logger.py. To create one file from both sources is a no go,
later I will add additional sources in the commons subdirectory. The production environment should
look as follows.

production_root/
 └── commons/
     ├── __init__.py
     └── shared library

How I have to do the implementation of the __init__.py and the setup.py file. I use python 3.10, setuptools 80.9
ans cython 3.2. I'm new in the user group, if a post exists, which solve my problem, than tell me this please.
Exists any small example projects for this kind of my problem ?

kindly regards,
henry

da-woods

unread,
Jan 12, 2026, 1:38:15 PM (2 days ago) Jan 12
to cython...@googlegroups.com

Hi,

Cython is essentially built around the model of "one source file"->"one shared library" so this isn't particularly well supported.

There are approaches to make it work - see https://github.com/dave-msk/merak or https://github.com/smok-serwis/snakehouse for prewrapped libraries or https://stackoverflow.com/questions/30157363 for a general guide. But be prepared for it not to work very well.

David

--

---
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/cython-users/c3998132-1f5b-4c68-aeac-32508ef9d604n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages