Tag: Python

  • Python Module of the day

    Who hasn’t been waiting to use Perl from Python? With this python module you can. As easy as import perl:

    >>> import perl
    >>> value = "Hello there"
    >>> if value =~ /^hello (.+?)$/i:
    ...     print("Found greeting:", $1)
    ...
    Found greeting: there
    >>> value =~ s/there/world/
    >>> print(value)
    Hello world

    https://pypi.org/project/perl/

  • The Dropbox journey to static type checking with Python

    Type Annotation is a feature that allows Python to maintain it’s dynamic typing and enable option static typing in the same code base. With the arrival of Python 3.5, the language implemented PEP 484, that describes a syntax to annotate code with type hints. Dropbox took a journey to leverage this option on 4 million lines of code for better quality. Here are their experiences.

    Combined count of type annotated lines of code.
    Type annotation

    Dropbox is a big user of Python. It’s our most widely used language both for backend services and the desktop client app (we are also heavy users of Go, TypeScript, and Rust).

    Source: Our journey to type checking 4 million lines of Python | Dropbox Tech Blog

  • Python 3.8.0b4 is now available for testing

    It’s time for the last beta release of Python 3.8. Go find it at: https://www.python.org/downloads/release/python-380b4/ This release is the last of four planned beta release previews. Beta release previews are intended to give the wider community the opportunity to test new features and bug fixes and to prepare their projects to support the new feature release.

    Source: Python 3.8.0b4 is now available for testing

  • Get started with Kubernetes (using Python)

    Jason Haley wrote a brief tutorial to get the Pythonista started with Kubernetes. Worth reading if you are new to the topic.

    Enable Kubernetes in Docker Desktop

    So, you know you want to run your application in Kubernetes but don’t know where to start. Or maybe you’re getting started but still don’t know what you don’t know. In this blog you’ll walk through how to containerize an application and get it running in Kubernetes.This walk-through assumes you are a developer or at least comfortable with the command line (preferably bash shell).

    Source: Get started with Kubernetes (using Python) – Kubernetes

  • Celery Worker wide configuration

    Celery is a distributed task execution environment for Python. While the emphasis is on distributed in this software, the concept of having workers allows for settings beyond the individual task. While the first rule of optimisation is “don’t”, sharing database connections is a low hanging fruit in most cases. And this can be configured per worker with Celery provided signals. To create a database connection for individual worker instances, leverage these signals to create the connection when the worker starts.

    This can be achieved leveraging the worker_process_init signal, and the corresponding worker_process_shutdown signal to clean up when the worker shuts down.

    The code should obviously be picked up at worker start, hence the tasks.py file will be a good location to keep these settings.

    Example tasks.py:

    from celery.signals import worker_process_init
    from celery.signals import worker_process_shutdown
    
    app = Celery('tasks', broker=CELERY_BROKER_URL)
    db = None
    
    @worker_process_init.connect
    def init_worker(**kwargs):
      global db
      log.debug('Initializing database connection for worker.')
      db = sqlite3.connect("urls.sqlite")
    
    @worker_process_shutdown.connect
    def shutdown_worker(**kwargs):
      global db
      if db:
        log.debug('Closing database connectionn for worker.')
        db.close()
    

    The example above opens a connection to a sqlite3 database, which in itself has other issues, but is only meant as an example. This connection is established for each individual worker at startup.

  • Pillow 3-0-0 is out

    The Pillow Team is excited to announce the release of Pillow 3.0.0.

    via: Alex Clark

  • Python 3.5 released

    LWN reports that Python 3.5 has been released today. Here is, what’s new.

  • Spectrum 2015 Programming Languages

    New languages enter the scene, and big data makes its mark

    Spoiler: basically, all is the same as past year, but R made a jump up by 4 positions and ranks 6th now. R is a statistical language, capable of munging huge amounts of data, hence the Big Data reference in the article.

    via: Spectrum

  • Python for Data Analysis

    Für alle Daten, die für Excel zu groß und für Hadoop zu klein sind. Oder um Analysen zu automatisieren, natürlich.