Skip to main content

neon_api: Python API wrapper for the Neon API.

neon_api is a Python wrapper designed to simplify interactions with the Neon API. It provides a convenient way for developers to integrate their Python applications with the Neon platform, offering methods to manage API keys, projects, branches, databases, endpoints, roles, and operations programmatically.

With neon_api, you can automate tasks, streamline workflows, and build powerful integrations with ease.

Installation

Installation of neon_api is easy, with pip:

$ pip install neon-api

Usage

from neon_api import NeonAPI

# Initialize the client.
neon = NeonAPI(api_key='your_api_key')

Documentation is available on ReadTheDocs.

Remember that you should never expose your api_key and handle it carefully since it gives access to sensitive data. It's better to set it as an environment variable (e.g. NEON_API_KEY + accompanying neon_api.from_environ()).


Methods of the NeonAPI class:

  • me(): Returns the current user.

Manage API keys:

  • api_keys(): Returns a list of API keys.
  • api_key_create(**json): Creates an API key.
  • api_key_delete(key_id): Deletes a given API key.

Manage projects:

  • projects(): Returns a list of projects.
  • project(project_id): Returns a specific project.
  • project_create(project_id, **json): Creates a new project.
  • project_update(project_id, **json): Updates a given project.
  • project_delete(project_id): Deletes a given project.
  • project_permissions(project_id): Returns a list of permissions for a given project.
  • project_permissions_grant(project_id, **json): Grant permissions to a given project.
  • project_permissions_revoke(project_id, **json): Revoke permissions from a given project.
  • connection_uri(project_id, database_name, role_name): Returns the connection string for a given project.

Manage branches:

  • branches(project_id): Returns a list of branches for a given project.
  • branch(project_id, branch_id): Returns a specific branch.
  • branch_create(project_id, **json): Creates a new branch.
  • branch_update(project_id, branch_id, **json): Updates a given branch.
  • branch_delete(project_id, branch_id): Deletes a given branch.
  • branch_set_as_primary(project_id, branch_id): Sets a given branch as primary.

Manage databases:

  • databases(project_id, branch_id): Returns a list of databases for a given project and branch.
  • database(project_id, branch_id, database_id): Returns a specific database.
  • database_create(project_id, branch_id, **json): Creates a new database.
  • database_update(project_id, branch_id, **json): Updates a given database.
  • database_delete(project_id, branch_id, database_id): Deletes a given database.

Manage endpoints:

  • endpoints(project_id, branch_id): Returns a list of endpoints for a given project and branch.
  • endpoint_create(project_id, branch_id, **json): Creates a new endpoint.
  • endpoint_update(project_id, branch_id, endpoint_id, **json): Updates a given endpoint.
  • endpoint_delete(project_id, branch_id, endpoint_id): Deletes a given endpoint.
  • endpoint_start(project_id, branch_id, endpoint_id): Starts a given endpoint.
  • endpoint_suspend(project_id, branch_id, endpoint_id): Suspends a given endpoint.

Manage roles:

  • roles(project_id, branch_id): Returns a list of roles for a given project and branch.
  • role(project_id, branch_id, role_name): Returns a specific role.
  • role_create(project_id, branch_id, role_name): Creates a new role.
  • role_delete(project_id, branch_id, role_name): Deletes a given role.
  • role_password_reveal(project_id, branch_id, role_name): Reveals the password for a given role.
  • role_password_reset(project_id, branch_id, role_name): Resets the password for a given role.

Manage operations:

  • operations(project_id): Returns a list of operations for a given project.
  • operation(project_id, operation_id): Returns a specific operation.

Experimental:

  • consumption(): Returns a list of project consumption metrics.

View the Neon API documentation for more information on the available endpoints and their parameters.

Development

First, create a virtual environment, then install the dependencies of the library with pip:

$ pip install -r requirements.txt

This will install all the necessary dependencies for development.

To run the tests, use the following command:

# set up a .env file with your API key as per `.env.example`
$ make test

The tests don't require an internet connection, as they are mocked using the pytest-vcr library. To record new cassettes, use the following command:

$ make record

This will record new cassettes for the tests. Make sure to commit these cassettes along with your changes.

Updating the schema

In order to update the Python data types from the OpenAPI schema, you need to:

$ mkdir neon_client/
$ make schema
# Now, take `neon_client/schema.py` and replace `neon_api/schema.py` with it.
# Now, run:
$ make test
# You may have to run `make record` to update the fixtures.

License & Copyright

Apache 2.0 Licensed.

Release files for neon-api 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for neon-api 0.3.0
File Size Uploaded
neon_api-0.3.0.tar.gz 20.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for neon-api 0.3.0
File Interpreter ABI Platform
neon_api-0.3.0-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size:37.1 kB

Release files / neon_api-0.3.0.tar.gz

Download URL neon_api-0.3.0.tar.gz
Size 20.2 kB
Tags Source
SHA-256 checksum
How to use checksums
6b4b8b27e8e57b27d127de2cdd41a65c157bedcf6f133ae243a747b17ff5abc0
BLAKE2b-256 checksum
How to use checksums
9d5f228116779ab3607de18ff476f843c2e7ea3c93c82fabe2129ecea2d988da
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.13.0

Release files / neon_api-0.3.0-py2.py3-none-any.whl

Download URL neon_api-0.3.0-py2.py3-none-any.whl
Size 16.9 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
eb4e47a0a1d53f64380defa05a207c80959263334b98442c8685a36fa1c77183
BLAKE2b-256 checksum
How to use checksums
20c775e0c12af22702b73795719c34e1da8859873b967b04f5dd9f53cdcd4aae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.13.0

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.0

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page