https://github.com/datastaxdevs/astrapy
https://github.com/datastaxdevs/astrapy
Last synced: 10 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/datastaxdevs/astrapy
- Owner: datastaxdevs
- License: apache-2.0
- Created: 2023-10-05T00:12:28.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-10-12T21:33:47.000Z (over 2 years ago)
- Last Synced: 2023-11-08T05:57:42.336Z (over 2 years ago)
- Language: Python
- Size: 267 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
## AstraPy
[](https://github.com/datastax/astrapy/actions)
AstraPy is a Pythonic SDK for [DataStax Astra](https://astra.datastax.com) and [Stargate](https://stargate.io/)
### Resources
- [DataStax Astra](https://astra.datastax.com)
- [Stargate](https://stargate.io/)
### Getting Started
Install AstraPy
```shell
pip install astrapy
```
Setup your Astra client
Create a .env file with the appropriate values, or use the 'astra' cli to do the same.
```bash
ASTRA_DB_KEYSPACE=""
ASTRA_DB_APPLICATION_TOKEN=""
ASTRA_DB_REGION=""
ASTRA_DB_ID=
```
Load the variables in and then create the client. This collections client can make non-vector and vector calls, depending on the call configuration.
```python
from astrapy.collections import AstraCollectionClient
from astrapy.base import AstraClient
from dotenv import load_dotenv
load_dotenv()
ASTRA_DB_ID = os.environ.get("ASTRA_DB_ID")
ASTRA_DB_REGION = os.environ.get("ASTRA_DB_REGION")
ASTRA_DB_APPLICATION_TOKEN = os.environ.get("ASTRA_DB_APPLICATION_TOKEN")
ASTRA_DB_KEYSPACE = os.environ.get("ASTRA_DB_KEYSPACE")
TEST_COLLECTION_NAME = "test_collection"
astra_client = AstraClient(
astra_database_id=ASTRA_DB_ID,
astra_database_region=ASTRA_DB_REGION,
astra_application_token=ASTRA_DB_APPLICATION_TOKEN,
)
vector_client = AstraVectorClient(astra_client=astra_client)
test_namespace = vector_client.namespace(ASTRA_DB_KEYSPACE)
test_collection = vector_client.namespace(ASTRA_DB_KEYSPACE).collection(TEST_COLLECTION_NAME)
```
####Getting started
Check out the [notebook](https://colab.research.google.com/github/synedra/astra_vector_examples/blob/main/notebook/vector.ipynb#scrollTo=f04a1806) which has examples for finding and inserting information into the database, including vector commands.
Take a look at the [vector tests](https://github.com/datastax/astrapy/blob/master/tests/astrapy/test_collections.py) and the [collection tests](https://github.com/datastax/astrapy/blob/master/tests/astrapy/test_collections.py) for specific endpoint examples.
#### Using the Ops Client
You can use the Ops client to work the with Astra DevOps API. Check the [devops tests](https://github.com/datastax/astrapy/blob/master/tests/astrapy/test_devops.py)