Git Product home page Git Product logo

python_udp_server's Introduction

Python UDP server using asyncio

status last-commit issues-pr-raw release license

This small project comprises a simple Python UDP server plus Dockerfile, as well as a (hopefully) useful Makefile and unittests.

The server makes use of the asyncio and uvloop libraries to allow for fast, asynchronous request handling.

Check out this blog post if you're interested in more performance details.

Prerequisites

python python-2

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.

The code is run and tested with Python 3.7.7 on macOS 10.14.6 and Python 3.8.5 on Ubuntu 18.04.5.

Environment

Clone the repo to your local machine.

Create a virtual environment for Python 3 with:

python3 -m pip install virtualenv
python3 -m virtualenv -p python3 env

Activate the virtual environment with:

source env/bin/activate

Install the required Python packages with:

pip3 install -r requirements.txt

Run the app without Docker

Quickstart (see below for flags, or use -h):

python3 app.py

Stop with Ctrl+C.

Run the app with Docker

Make sure you have Docker installed locally:

docker -v

Quickstart:

make build && make run

Alternatively, build the image locally with:

docker build --tag emoji-app:latest .

Or:

make build

Then, run the container locally with:

docker run --rm --name emoji-app -p 3001:3001/udp emoji-app:latest

Or:

make run

Optionally, the following flags can be used: --n, --r, --s and --h/-h:

  • --n Multiply number of emojis by n (int, default: 1)
  • --r Disable translation from keyword to emoji (bool, default: False)
  • --s Separator between each emoji (str, default: "")
  • --h/-h See usage information

For example:

docker run --rm --name emoji-app -p 3001:3001/udp emoji-app:latest --n 2 --r True --s "+"

In another shell session, you can now trigger the endpoint (0.0.0.0:3001), for example using nc:

nc -u 0.0.0.0 3001

Send a message and hit enter:

2 :ok:

Development and testing

Using the Makefile you can run make <cmd> where <cmd> is one of:

  • sort-imports to ensure Python imports are in the correct PEP format/order
  • format to format Python files using black
  • type-check to run static type checking using mypy
  • test to run unittests using pytest
  • all to run all steps (or just type make)

Authors

  • Manuel Zander

Acknowledgments

Many thanks to julvo for his review and great suggestions during development of this software ๐Ÿ˜Š

python_udp_server's People

Contributors

manuelzander avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.