Giter VIP home page Giter VIP logo

cntxt's Introduction

cntxt - the missing Python namespace

cntxt adds a dynamic namespace that is managed with a context manager and extends down through the call stack, to be accessible where needed.

Other options for managing namespaces

Scopes:

  1. Local scope - variables in the current function or class definition
  2. Enclosing scope - variables available through lexical closure
  3. Global scope - module namespace created when module is loaded, usually never deleted
  4. Built-in scope - created when interpreter starts, never deleted

Namespaces: 5. Object namespace - attributes, inherited or not 6. Class namespace - same, but for classes 7. Thread-local - data specific to a thread 8. Environment variables - values defined outside the Python program 9. File, database or similar - containing key-value pairs or more complex data

What's wrong with these namespaces?

  1. Local scope is too local, not available elsewhere.
  2. Enclosing scope is a little bit less local, but still very local in terms of a codebase.
  3. Global scope is too global - we try to avoid "polluting the global namespace" as the values can be overwritten anywhere and conflicts can be hard to debug.
  4. Built-in scope is too static.
  5. Instances are ok, but accessing them requires a reference, which you have to manually pass down the stack to any users.
  6. Classes are often used as importable singletons for configuration type information, but as such they can be "too global" and modified in surprising places.
  7. Thread-local data is "too global" within the thread stack.
  8. Environment variables are essentially global values, and where they are defined is not visible in the Python code.
  9. Files or more powerful require configuration information to be accessible. They are also not in memory, which may be relevant in some cases.

cntxt's People

Contributors

holvi-mikael avatar mikaelho avatar

Watchers

 avatar

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.