Giter VIP home page Giter VIP logo

neon-api-python's Introduction

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.

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:

$ 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.

License & Copyright

Apache 2.0 Licensed.

neon-api-python's People

Contributors

dependabot[bot] avatar kennethreitz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

kennethreitz

neon-api-python's Issues

API returns 200 for DELETE for deleted projects

Steps to reproduce

  • create a project
  • Send a DELETE:
DEBUG: https://console.neon.tech:443 "DELETE /api/v2/projects/small-mouse-01401992 HTTP/1.1" 200 1005
INFO: Project deleted
  • Send another DELETE:
DEBUG: https://console.neon.tech:443 "DELETE /api/v2/projects/small-mouse-01401992 HTTP/1.1" 200 577
1 validation error for ProjectResponse
project.provisioner
  Input should be 'k8s-pod' or 'k8s-neonvm' [type=enum, input_value='', input_type=str]
    For further information visit https://errors.pydantic.dev/2.7/v/enum
  • Send a DELETE for a project which did never exist:
DEBUG: https://console.neon.tech:443 "DELETE /api/v2/projects/small-mouse-01501992 HTTP/1.1" 404 66

Expected result

Once the project is deleted, this should return a 404.

Actual result

Instead a 200 is returned, and an error message in the response.

Environment

small-mouse-01401992
    Name:          small-mouse-01401992
    Region:        aws-us-east-2
    Platform ID:   aws
    PG Version:    16
    Proxy Host:    us-east-2.aws.neon.tech
    Active Time:   0
    Storage Size:  0
    Last Active:   None

Python 3.11.4, latest neon-api package.

Additional information

For now I'm handling this in my script as follow:

    try:
        project = neon.project_delete(arguments[0])
        logging.info("Project deleted")
    except NeonAPIError as err:
        err_dict = json.loads(str(err))
        if "projects not found" in err_dict.get('message'):
            logging.error("Project not found!")
    except ValidationError as err:
        # this error is thrown when an already deleted project is deleted again
        logging.error("Project not found!")

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.