Category archives for Python

Dockerizing python with ssdeep dependency

The official  python docker container does exactly what it should. It automatically copies the requirements.txt  file and your current directory into /usr/src/app. It should then automatically pip install the dependencies from the requirements.txt, before running the actual Dockerfile commands But sometimes python libraries require additional system setups by themselves (one might consider it a pip bug..). For example, working with ssdeep, a […]

Python design patterns #5: observer (aka: pub-sub)

The observer is probably the GOF pattern with the most impact on networking. It is a massaging pattern by itself. It’s quite simple, though. The subscribers, interested with a certain topic, subscribe with a publisher for updates regarding that topic. The publisher, triggered by our topic-aware system, then publishes the topic updates to the right subscribers. Use case Every […]

Python design patterns #4: visitor

Another favorite. Much simpler than the decorator, but sleeker no less:) Who left the door open? What if we could let someone operate over our object, whoever that someone was, whatever our object looks like and for any possible reason? Intuitively a door left open comes to mind. Its not a matter of having the […]

Python design patterns #3: the decorator

Continuing with one of my favorites – the decorator. It’s a smart one, so a little more talking before coding..   Why? What do you do when you need a flexible combination of properties in an object? If you’re thinking why not sub-classing? you’re ok.. Sub classing is just right for allowing slightly different flavors […]

Python design patterns #2: adapter, bridge and proxy

Finally got the time to complete this project, since I first started it with the classic Singleton. Later I’ll post about the Borg pattern, which is the pythonic version of how singleton should have been.. ———— Adapter, Bridge and Proxy are all about can’t / won’t / prefer-not-to do something directly, but by other mean. They’re […]

Singleton pattern for Python (single and multi-threaded)

Goals: Provide single point of access, to a one and only instance of a class Support lazy (on-demand) instantiation Support single and multi-threaded RT environment Challenges: Python does not support constructor hiding (i.e. marking as private) Proving I’m right – CPython does not really support multi-threading, due to its Global Interpreter Lock What’s good here? Instead of […]

mongoDB over python in 10 minutes

Install mongoDB – a great, yet simple, document oriented NoSQL DB  Install PyMongo – looks like the simplest Python driver for mongoDB (needs Python, of course) Start querying in no time! To read some more: About mongoDB About BSON format Basic CRUD operations

svg support for app engine running python on windows xp

While investigating app engine – svgz support (I’ll have a separate post for that) I encountered an even more basic issue: an app engine development server running on windows xp has no svg support at all. Every svg file referenced in a page is downloaded by the browser A closer look revealed a wrong response header for […]

Python – referencing a class from another Python file

Use the “from” keyword in addition to “import”, to reference the other file Syntax: from other_file_name import class_name_to_import Example: file first.py has class A definition To use in file second.py, add to the header of second.py: from first import A …