Package: aind-data-access-api
aind-data-access-apiAPI to interact with a few AIND databases.UsageWe have two primary databases. A Document store to keep unstructured json documents, and a relational database to store structured tables.Document StoreWe have some convenience methods to interact with our Document Store. You can create a client by explicitly setting credentials, or downloading from AWS Secrets Manager.from aind_data_access_api.credentials import DocumentStoreCredentials
from aind_data_access_api.document_store import Client

# Method one assuming user, password, and host are known
ds_client = Client(
            credentials=DocumentStoreCredentials(
                username="user",
                password="password",
                host="host",
                database="metadata",
            ),
            collection_name="data_assets",
        )

# Method two if you have permissions to AWS Secrets Manager
ds_client = Client(
            credentials=DocumentStoreCredentials(
                aws_secrets_name="aind/data/access/api/document_store/metadata"
            ),
            collection_name="data_assets",
        )

# To get all records
response = list(ds_client.retrieve_data_asset_records())

# To get a list of filtered records:
response = list(ds_client.retrieve_data_asset_records({"subject.subject_id": "123456"}))RDS TablesWe have some convenience methods to interact with our Relational Database. You can create a client by explicitly setting credentials, or downloading from AWS Secrets Manager.from aind_data_access_api.credentials import RDSCredentials
from aind_data_access_api.rds_tables import Client

# Method one assuming user, password, and host are known
ds_client = Client(
            credentials=RDSCredentials(
                username="user",
                password="password",
                host="host",
                database="metadata",
            ),
            collection_name="data_assets",
        )

# Method two if you have permissions to AWS Secrets Manager
ds_client = Client(
            credentials=RDSCredentials(
                aws_secrets_name="aind/data/access/api/rds_tables"
            ),
        )

# To retrieve a table as a pandas dataframe
df = ds_client.read_table(table_name="spike_sorting_urls")

# Can also pass in a custom sql query
df = ds_client.read_table(query="SELECT * FROM spike_sorting_urls")

# It's also possible to save a pandas dataframe as a table. Please check internal documentation for more details.
ds_client.overwrite_table_with_df(df, table_name)InstallationTo use the software, it can be installed from PyPI.pipinstallaind-data-access-apiTo develop the code, clone repo and runpipinstall-e.[dev]ContributingLinters and testingThere are several libraries used to run linters, check documentation, and run tests.Please test your changes using thecoveragelibrary, which will run the tests and log a coverage report:coveragerun-munittestdiscover&&coveragereportUseinterrogateto check that modules, methods, etc. have been documented thoroughly:interrogate.Useflake8to check that code is up to standards (no unused imports, etc.):flake8.Useblackto automatically format the code into PEP standards:black.Useisortto automatically sort import statements:isort.Pull requestsFor internal members, please create a branch. For external members, please fork the repository and open a pull request from the fork. We'll primarily useAngularstyle for commit messages. Roughly, they should follow the pattern:<type>(<scope>): <short summary>where scope (optional) describes the packages affected by the code changes and type (mandatory) is one of:build: Changes that affect build tools or external dependencies (example scopes: pyproject.toml, setup.py)ci: Changes to our CI configuration files and scripts (examples: .github/workflows/ci.yml)docs: Documentation only changesfeat: A new featurefix: A bugfixperf: A code change that improves performancerefactor: A code change that neither fixes a bug nor adds a featuretest: Adding missing tests or correcting existing testsSemantic ReleaseThe table below, fromsemantic release, shows which commit message gets you which release type whensemantic-releaseruns (using the default configuration):Commit messageRelease typefix(pencil): stop graphite breaking when too much pressure appliedPatchFix Release, Default releasefeat(pencil): add 'graphiteWidth' optionMinorFeature Releaseperf(pencil): remove graphiteWidth optionBREAKING CHANGE: The graphiteWidth option has been removed.The default graphite width of 10mm is always used for performance reasons.MajorBreaking Release(Note that theBREAKING CHANGE:token must be in the footer of the commit)DocumentationTo generate the rst files source files for documentation, runsphinx-apidoc-odoc_template/source/srcThen to create the documentation HTML files, runsphinx-build-bhtmldoc_template/source/doc_template/build/htmlMore info on sphinx installation can be foundhere.