semvec/pypi-packages huggingface dataset:
morpho-ga 1.0.0
GA Client Component of the Morpho Design Explorer Project. This client provides the `GASearch` class interface to connect to a MorphoDesignExplorer backend, load project schemas and existing generated models, and generate new children with custom fitness functions.
Requires Python: >=3.8

# Morpho Design Explorer - GA Client

This is the GA Client Component of the Morpho Design Explorer Project. This client provides the `GASearch` class interface to connect to a MorphoDesignExplorer backend, load project schemas and existing generated models, and generate new children with custom fitness functions.

Sample usage is as follows:
```python
# Import the search interface class
from morpho_ga import GASearch

# Define the server location URL and the project identifier for the project to operate on
SERVER_URL, project_id = "server_url_here", "project_id here"

# build the search interface and load generated models from SERVER_URL
search_object = GASearch(SERVER_URL, project_id)

# generate a child with the following fitness function: 2 <= step < 7
print(search_object.generate_child((Q.step >= 2) & (Q.step < 7)))

# get auth token from the server; will trigger a CLI prompt for a username, password and OTP
search_object.get_token()

# dump all generated models to the server in bulk
search_object.put_records()
```

The `generate_child()` method generates one child at a time. This offers great flexibility in generating a varying number of children with different fitness functions. An example is given below to demonstrate the same:

```python
iterations = 0
unique = 0
while True:
    if unique == 10:
        break
    if unique < 5:
        # generate 5 children with random genes, from the pool with `step` > 0
        child = search_object.generate_child(Q.step > 0, parent_count=0)
    elif unique >= 5:
        # generate 5 more random chilren with genes crossed over from 2 parents, with 2 <= step < 7
        child = search_object.generate_child((Q.step >= 2) & (Q.step < 7), parent_count=0)
    if child is not None:
        # bump unique if child is not a duplicate
        unique += 1
    iterations += 1

search_object.put_records()
```

### Todo

- [ ] Don't upload the entire set of records on generation of each child; only upload new children.
- [ ] Fetch username and password from a file and Fetch OTP from the CLI or through a CLI option.
- [ ] Detect and report malformed Server URLs passed.


### References

1. Paragen System Reference: https://www.ingentaconnect.com/content/iass/jiass/2012/00000053/00000004/art00010
flaskws3 3.0.4.1
WebSockets for Flask.

# `flaskws3`

# BIG NOTE: the code is broken for some reason.

Actually good WebSocket for Flask.

Keep in mind that this is just a patched version of [this Python 2 original](https://github.com/smallfz/flask-ws); no changes were made, so original docs are still valid.

For convenience, the module name didn't change too.

## Usage

Info is *mostly* taken from the original docs.

Here's some starting code for this mini tutor:

```py
import flaskws

app = Flask(__name__)
app.wsgi_app = flaskws.WsMiddleware(app.wsgi_app)
```
<!-- # app.run() -->

### Splitted path!

#### Method #1

For this method, simply create a class for your WebSocket server.

```py
@app.route("/ws/<int:some_id>")
@flaskws.ws_server
class SampleServer():
	def __init__(self, ws_sock, **req_args):
		self.ws_sock = ws_sock
		print(req_args["some_id"])
	def on_open(self, ws_sock): pass
	def on_message(self, ws_sock, frame):
		fin, op, payload = frame # TODO: Search around code to find what info lurks in `frame`.
	def on_close(self, ws_sock): pass
```

#### Method #2

This method uses a function. A little harder to control than Method #1, but no one says you can't pick this one!..

```py
@app.route("/ws/<int:some_id>")
@flaskws.ws_server_view
def echo_server(ws_sock, some_id=None):
	while True:
		frame = ws_sock.recv(timeout=5.0)
		if frame:
			fin, op, msg = frame
			if msg:
				ws_sock.send(msg)
				if msg == "close": # Likely a module-implemented way of closing??
					break
```

## Client

As in the unpatched version, there's also a client. The client wasn't changed in any way. Still no SSL support though...

Here's some sample code for you:

```py
from flaskws import ws_connect

with ws_connect("ws://example.com/wsgateway/") as ws: # Could be used as a class too, just remember to `close()`!!
	if ws.handshake():
		ws.send("somethingsomething")
		for frame in c:
			print(frame)
```
dockerctx 2024.3.2
A context manager for a docker container. 

.. image:: https://github.com/cjrh/dockerctx/workflows/Python%20application/badge.svg
    :target: https://github.com/cjrh/dockerctx/actions

.. image:: https://coveralls.io/repos/github/cjrh/dockerctx/badge.svg?branch=master
    :target: https://coveralls.io/github/cjrh/dockerctx?branch=master

.. image:: https://img.shields.io/pypi/pyversions/dockerctx.svg
    :target: https://pypi.python.org/pypi/dockerctx

.. image:: https://img.shields.io/github/tag/cjrh/dockerctx.svg
    :target: https://github.com/cjrh/dockerctx

.. image:: https://img.shields.io/pypi/v/dockerctx.svg
    :target: https://img.shields.io/pypi/v/dockerctx.svg

dockerctx
=========

*dockerctx* is a context manager for managing the lifetime of a docker container.

The main use case is for setting up scaffolding for running tests, where you want
something a little broader than *unit tests*, but less heavily integrated than,
say, what you might write using `Robot framework`_.

.. _Robot framework: http://robotframework.org/

Install
-------

.. code-block:: bash

    $ pip install dockerctx


The development-specific requirements will be installed automatically.

.. _flit: https://flit.readthedocs.io/en/latest/

Demo
----

This is taken from one of the tests:

.. code-block:: python3

    import time
    import redis
    import pytest
    from dockerctx import new_container

    # First make a pytest fixture

    @pytest.fixture(scope='function')
    def f_redis():

        # This is the new thing! It's pretty clear.  The `ready_test` provides
        # a way to customize what "ready" means for each container. Here,
        # we simply pause for a bit.

        with new_container(
                image_name='redis:latest',
                ports={'6379/tcp': 56379},
                ready_test=lambda: time.sleep(0.5) or True) as container:
            yield container

    # Here is the test.  Since the fixture is at the "function" level, a fully
    # new Redis container will be created for each test that uses this fixture.
    # After the test completes, the container will be removed.

    def test_redis_a(f_redis):
        # The container object comes from the `docker` python package. Here we
        # access only the "name" attribute, but there are many others.
        print('Container %s' % f_redis.name)
        r = redis.StrictRedis(host='localhost', port=56379, db=0)
        r.set('foo', 'bar')
        assert r.get('foo') == b'bar'

Note that a brand new Redis container is created here, used within the
context of the context manager (which is wrapped into a *pytest* fixture
here), and then the container is destroyed after the context manager
exits.


In the src, there is another, much more elaborate test which

#. runs a *postgres* container;
#. waits for postgres to begin accepting connections;
#. creates a database;
#. creates tables (using the SQLAlchemy_ ORM);
#. performs database operations;
#. tears down and removes the container afterwards.

.. _SQLAlchemy: http://www.sqlalchemy.org/