Start Elasticsearch with Python (for testing or other purposes)
Project description
Start Elasticsearch using Python.
Settings
elasticsearch_test.ElasticsearchTest( port=1234 es_path='/home/maria/elasticsearch-5.2.4' data_dir='/home/maria/es-data' es_java_opts='-Xms512m -Xmx512m' )
port
Default: 9200
es_path
Path to the Elasticsearch directory (home of /bin). Default: uses $ES_HOME
es_java_opts
Sets $ES_JAVA_OPTS for process to this value if present.
data_dir
Directory to place /data and /logs in. Default: uses tempfile.
Running
import time import elasticsearch_test instance = elasticsearch_test.ElasticsearchTest() # This blocks until either an error is found # or Elasticsearch has been initialized. instance.start() # or instance.start(block=False) while True: if instance.is_started(): break time.sleep(1)
Testing
Use it as a resource::
import elasticsearch_test import elasticsearch with elasticsearch_test.ElasticsearchTest() as instance: connection_info = instance.get_connection_info() client = elasticsearch.Elasticsearch(connection_info)
Use it as a Pytest fixture::
import elasticsearch_test @pytest.fixture(scope="session") def es(): instance = elasticsearch_test.ElasticsearchTest() instance.start() yield instance instance.stop()
When using data_dir, if there are preexisting data in the directory, you should also wait for the data to be initialized::
with elasticsearch_test.ElasticsearchTest(data_dir='my_data') as instance: while not instance.is_data_initialized(): time.sleep(1) # do something!
Test this package
Needed: pyenv and the plugin pyenv-virtualenv.
Create a normal virtualenv and activate it
Install extras pip install .[testing]
Install the needed Python versions using pyenv: 3.4, 3.5, 3.6, 3.7
Setup virtualenvs for all but the Python version you are using, for example if you use 3.4
$ pyenv virtualenv -p python3.5 3.5.6 py35 $ pyenv virtualenv -p python3.6 3.6.6 py36 $ pyenv virtualenv -p python3.7 3.7.1 py37
Activate everything and run tox:
$ pyenv shell py35 py36 py37 $ source ./venv/bin/activate $ tox
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file elasticsearch-test-py-1.1.0.tar.gz
.
File metadata
- Download URL: elasticsearch-test-py-1.1.0.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.5.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0d64685f19eff5061d3f9652ab482f49b85c02626aa3a50a93eb5526a7311d3 |
|
MD5 | 5f5b68ff30e05e6a69358c145d5f6e23 |
|
BLAKE2b-256 | 8142ea876c2a8438e2d0f3cdf1d1dda9459fbef026d0e6fcd18b6b12beeff55b |
File details
Details for the file elasticsearch_test_py-1.1.0-py2.py3-none-any.whl
.
File metadata
- Download URL: elasticsearch_test_py-1.1.0-py2.py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.5.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 22b887da276842af139ce475b197834bb32644a8e2ddc90e45c96c5b2560bb0c |
|
MD5 | a9f3f2cfc17b018cb3d6710cfc0f15fc |
|
BLAKE2b-256 | fd1503c61395f0e87a94bb661e677e03af86815842900dffac6adde8622ed27d |