Giter VIP home page Giter VIP logo

async_http_test's Introduction

Async HTTP Test

Python version Environment Coding style

Trying to get some basic examples of using an API with async

Resources

Install

Download source code

git clone https://github.com/DavidTWynn/async_http_test
cd async_http_test

Create virtual environment

py -3.11 -m venv venv
venv/Scripts/activate

Upgrade pip

py -m pip install --upgrade pip

Use pip to install the project and dependencies

pip install -e .

Optional: Install dev dependencies to contribute

pip install -e .[dev]

Settings

The postgres database is setup with Docker compose. The postgres settings are configured with Docker secrets. These files will need to be created with the value stored for the setting. Create them at the top of the project level.

  • postgres_db.txt
  • postgres_password.txt
  • postgres-user.txt

Files

  • async_http_test/
    • async_http_test.py - Examples for http async requests
    • counter_async.py - sleep examples of sync and async
  • Dockerfile - Settings to create a Docker image for the project
  • .vscode/settings.json - MS VSCode IDE workspace settings for linting, formatting, etc. tests/ - pytest unit tests
  • .gitignore - Files to not track by git
  • .pre-commit-config.yaml - pre-commit hooks for git. Runs linting before committing
  • google_docstring.mustache - Python autodocstring extension template based on Google Python style guide
  • pyproject.toml - Project info, dependencies, and dev dependencies.
  • README.md - Overview of the project
  • .git - git change history files
  • venv - Created on demand for project virtual environment for Python dependencies

Run

counter_async.py

Shows how you can use async with sleep vs a sync version

python async_http_test/counter_async.py
Example output
One
One
One
Two
Two
Two
Async executed in 1.00 seconds.
One
Two
One
Two
One
Two
Sync executed in 3.00 seconds.

pre-commit hooks

Linting to be ran before committing

  • black
  • isort
  • flake8
  • bandit

Update pre-commit hooks

If a hook is added to .pre-commit-config.yaml, update the .git/hooks files

pre-commit install

Create Docker image

Using the Dockerfile, a new Docker image can be created locally. This needs to be done in the project directory.

Make sure project is up to date

git pull

Create image

docker build -t async_http_test .

Verify image

docker image ls

Run image

docker run -it -d --name async_http_test async_http_test

Verify running container

docker container ls -a

Enter container

docker exec -it async_http_test bash

Run 'exit' from shell when done.

For development, VSCode's "Dev Containers" extension can be used to remote into the container and open the project in the /app directory. The code can be ran normally in the container. When VSCode is connected to the container, the VSCode extensions will then need to be installed for development.

Clean up Docker

When development work is done with Docker, the container can be stopped and the image can be deleted.

Find container name

docker container ls

Name should be under NAMES column for "async_http_test" using that IMAGE

Stop the container

docker container stop async_http_test

Delete the container (Needs to be stopped first)

docker container rm async_http_test

Locate the image (should be 'async_http_test')

docker image ls

Delete the image

docker image rm async_http_test

async_http_test's People

Contributors

davidtwynn 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.